@@ -11,11 +11,13 @@ import org.gradle.tooling.events.task.TaskFinishEvent
1111import org.gradle.tooling.events.task.TaskStartEvent
1212import processing.app.Base
1313import processing.app.Messages
14+ import processing.app.Platform
1415import processing.app.ui.Editor
1516import java.io.File
1617import javax.swing.SwingUtilities
1718import javax.swing.event.DocumentEvent
1819import javax.swing.event.DocumentListener
20+ import kotlin.io.path.writeText
1921
2022// TODO: Embed the core, gradle plugin, and preprocessor in a custom .m2 repository
2123// Right now the gradle service only works if you publish those to the local maven repository
@@ -137,33 +139,42 @@ class GradleService(val editor: Editor) {
137139 // TODO: Research if we can generate these programmatically
138140 // Ideally they would not be placed into the sketch folder
139141
142+ val initGradle = kotlin.io.path.createTempDirectory().resolve(" init.gradle.kts" ).apply {
143+ val content = """
144+ beforeSettings{
145+ pluginManagement {
146+ repositories {
147+ maven { url = uri("${Platform .getContentFile(" repository" ).absolutePath} ") }
148+ //mavenLocal()
149+ gradlePluginPortal()
150+ }
151+ }
152+ }
153+ """ .trimIndent()
154+
155+ writeText(content)
156+ }
157+
140158 val buildGradle = folder.resolve(" build.gradle.kts" )
159+ // TODO: Manage script if the comment exists
141160 if (! buildGradle.exists()){
142161 Messages .log(" build.gradle.kts not found in ${folder} , creating one" )
143162 // TODO: Allow for other plugins to be registered
163+ // TODO: Allow for the whole configuration to be overridden
144164 val content = """
165+ // Managed by: Processing ${Base .getVersionName()}
166+ // If you delete this comment Processing will no longer update the build scripts
167+
145168 plugins{
146169 id("processing.java.gradle") version "${Base .getVersionName()} "
147170 }
148171 """ .trimIndent()
149172 buildGradle.writeText(content)
150173 }
151174
152- val settingsGradle = folder.resolve(" settings.gradle.kts" )
153- if (! settingsGradle.exists()){
154- Messages .log(" settings.gradle.kts not found in ${folder} , creating one" )
155- val content = """
156- pluginManagement {
157- repositories {
158- mavenLocal()
159- mavenCentral()
160- }
161- }
162- """ .trimIndent()
163- settingsGradle.writeText(content)
164- }
165-
166175 return this .newBuild()
176+ // .setJavaHome(Platform.getJavaHome())
177+ .withArguments(" --init-script" , initGradle.toAbsolutePath().toString())
167178 .addProgressListener(ProgressListener { event ->
168179 val name = event.descriptor.name
169180 if (event is TaskStartEvent ) {
@@ -179,6 +190,5 @@ class GradleService(val editor: Editor) {
179190 setStandardOutput(System .out )
180191 }
181192 }
182- // .setJavaHome(Platform.getJavaHome())
183193 }
184194}
0 commit comments