From e4b93a3dc7c84f67ca5ddea2a324ac9fe0758aff Mon Sep 17 00:00:00 2001 From: Tommy Ettinger Date: Sun, 20 Oct 2024 04:35:51 -0700 Subject: [PATCH] Weirdest. Fix. Ever. This commit is mostly an edited revert of a few previous commits, but also updates to Construo 1.4.2. That is a nice version bump because it makes the plugin more flexible about how and where it can be applied, which turned out to be critical when Kotlin and Android are both in use. This also reverts the settings.gradle changes because they were causing some trouble and I wasn't sure how to solve it. Similar code may work here in the future. --- build.gradle | 2 +- .../gdx/liftoff/data/files/ProjectFiles.kt | 23 +------- .../data/files/gradle/RootGradleFile.kt | 56 ++++++++++++++++--- .../gdx/liftoff/data/languages/Kotlin.kt | 1 + .../gdx/liftoff/data/platforms/Android.kt | 14 +++-- .../kotlin/gdx/liftoff/data/platforms/Core.kt | 50 +---------------- .../gdx/liftoff/data/platforms/Lwjgl3.kt | 6 +- 7 files changed, 67 insertions(+), 85 deletions(-) diff --git a/build.gradle b/build.gradle index fc18d61e..9fc813bb 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { } plugins { - id "io.github.fourlastor.construo" version "1.4.1" + id "io.github.fourlastor.construo" version "1.4.2" id "application" } diff --git a/src/main/kotlin/gdx/liftoff/data/files/ProjectFiles.kt b/src/main/kotlin/gdx/liftoff/data/files/ProjectFiles.kt index b44fe7af..4e871e81 100644 --- a/src/main/kotlin/gdx/liftoff/data/files/ProjectFiles.kt +++ b/src/main/kotlin/gdx/liftoff/data/files/ProjectFiles.kt @@ -138,28 +138,7 @@ class SettingsFile(val platforms: Iterable) : ProjectFile { override fun save(destination: FileHandle) { val content = platforms.joinToString( prefix = - """ -pluginManagement { - repositories { - google { - content { - includeGroupByRegex("com\\.android.*") - includeGroupByRegex("com\\.google.*") - includeGroupByRegex("androidx.*") - } - } - mavenCentral() - gradlePluginPortal() - } -} -dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) - repositories { - google() - mavenCentral() - } -} -// A list of which subprojects to load as part of the same larger project. + """// A list of which subprojects to load as part of the same larger project. // You can remove Strings from the list and reload the Gradle project // if you want to temporarily disable a subproject. include """, diff --git a/src/main/kotlin/gdx/liftoff/data/files/gradle/RootGradleFile.kt b/src/main/kotlin/gdx/liftoff/data/files/gradle/RootGradleFile.kt index fdd8aaf3..3540d9ec 100644 --- a/src/main/kotlin/gdx/liftoff/data/files/gradle/RootGradleFile.kt +++ b/src/main/kotlin/gdx/liftoff/data/files/gradle/RootGradleFile.kt @@ -43,15 +43,53 @@ allprojects { } } +configure(subprojects${if (project.hasPlatform(Android.ID)) { + " - project(':android')" + } else { + "" + }}) { +${plugins.joinToString(separator = "\n") { " apply plugin: '$it'" }} + sourceCompatibility = ${project.advanced.javaVersion} + + // From https://lyze.dev/2021/04/29/libGDX-Internal-Assets-List/ + // The article can be helpful when using assets.txt in your project. + tasks.register('generateAssetList') { + inputs.dir("${'$'}{project.rootDir}/assets/") + // projectFolder/assets + File assetsFolder = new File("${'$'}{project.rootDir}/assets/") + // projectFolder/assets/assets.txt + File assetsFile = new File(assetsFolder, "assets.txt") + // delete that file in case we've already created it + assetsFile.delete() + + // iterate through all files inside that folder + // convert it to a relative path + // and append it to the file assets.txt + fileTree(assetsFolder).collect { assetsFolder.relativePath(it) }.sort().each { + assetsFile.append(it + "\n") + } + } + processResources.dependsOn 'generateAssetList' + + compileJava { + options.incremental = true + }${if (plugins.contains("kotlin")) { + """ + compileKotlin.compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_${ + if (project.advanced.javaVersion.removePrefix("1.") == "8") { + "1_8" + } else { + project.advanced.javaVersion.removePrefix("1.") + }}) + """ + } else { + "" + }} +} + subprojects { version = '${'$'}projectVersion' ext.appName = '${project.basic.name}' -} - -eclipse.project.name = '${project.basic.name}' + '-parent' -""" -} -/* repositories { mavenCentral() maven { url 'https://s01.oss.sonatype.org' } @@ -66,4 +104,8 @@ eclipse.project.name = '${project.basic.name}' + '-parent' "" }} } - */ +} + +eclipse.project.name = '${project.basic.name}' + '-parent' +""" +} diff --git a/src/main/kotlin/gdx/liftoff/data/languages/Kotlin.kt b/src/main/kotlin/gdx/liftoff/data/languages/Kotlin.kt index 3d56b2d7..dc565602 100644 --- a/src/main/kotlin/gdx/liftoff/data/languages/Kotlin.kt +++ b/src/main/kotlin/gdx/liftoff/data/languages/Kotlin.kt @@ -17,6 +17,7 @@ class Kotlin : Language { override val version = "2.0.21" override fun initiate(project: Project) { + project.rootGradle.buildDependencies.add("\"org.jetbrains.kotlin:kotlin-gradle-plugin:\$kotlinVersion\"") project.rootGradle.plugins.add(id) project.platforms.values.forEach { project.files.add(SourceDirectory(it.id, path("src", "main", "kotlin"))) } if (project.hasPlatform(Android.ID)) { diff --git a/src/main/kotlin/gdx/liftoff/data/platforms/Android.kt b/src/main/kotlin/gdx/liftoff/data/platforms/Android.kt index d5d7e695..785f2da4 100644 --- a/src/main/kotlin/gdx/liftoff/data/platforms/Android.kt +++ b/src/main/kotlin/gdx/liftoff/data/platforms/Android.kt @@ -21,6 +21,7 @@ class Android : Platform { override val order = ORDER override val isStandard = false // user should only jump through android hoops on request override fun initiate(project: Project) { + project.rootGradle.buildDependencies.add("\"com.android.tools.build:gradle:8.5.2\"") project.properties["android.useAndroidX"] = "true" project.properties["android.enableR8.fullMode"] = "false" addGradleTaskDescription(project, "lint", "performs Android project validation.") @@ -144,13 +145,9 @@ buildscript { mavenCentral() google() } - dependencies { - classpath 'com.android.tools.build:gradle:8.5.2' - } } -plugins { - id "com.android.application" version "8.4.2" - ${if (latePlugin) " id 'org.jetbrains.kotlin.android' version '${project.languages.getVersion("kotlin")}'\n" else ""}} +${plugins.joinToString(separator = "\n") { "apply plugin: '$it'" }} +${if (latePlugin)"apply plugin: \'kotlin-android\'" else ""} android { namespace "${project.basic.rootPackage}" @@ -208,6 +205,11 @@ android { }} } +repositories { + // needed for AAPT2, may be needed for other tools + google() +} + configurations { natives } dependencies { diff --git a/src/main/kotlin/gdx/liftoff/data/platforms/Core.kt b/src/main/kotlin/gdx/liftoff/data/platforms/Core.kt index df59e87c..cfff0692 100644 --- a/src/main/kotlin/gdx/liftoff/data/platforms/Core.kt +++ b/src/main/kotlin/gdx/liftoff/data/platforms/Core.kt @@ -1,7 +1,6 @@ package gdx.liftoff.data.platforms import gdx.liftoff.data.files.gradle.GradleFile -import gdx.liftoff.data.languages.Kotlin import gdx.liftoff.data.project.Project import gdx.liftoff.views.GdxPlatform @@ -20,7 +19,7 @@ class Core : Platform { override val order = ORDER override val isStandard = false override fun createGradleFile(project: Project): GradleFile { - return CoreGradleFile(project) + return CoreGradleFile() } override fun initiate(project: Project) { @@ -32,58 +31,15 @@ class Core : Platform { /** * Gradle file of the core project. Should contain all multi-platform dependencies, like "gdx" itself. */ -class CoreGradleFile(val project: Project) : GradleFile(Core.ID) { +class CoreGradleFile : GradleFile(Core.ID) { init { addDependency("com.badlogicgames.gdx:gdx:\$gdxVersion") } override fun getContent(): String { - return """ -plugins { - id "java-library" -${if ( project.rootGradle.plugins.contains("kotlin")) " id 'org.jetbrains.kotlin.jvm' version '${project.languages.getVersion("kotlin")}'\n" else ""}} - -// From https://lyze.dev/2021/04/29/libGDX-Internal-Assets-List/ -// The article can be helpful when using assets.txt in your project. -tasks.register('generateAssetList') { - inputs.dir("${'$'}{project.rootDir}/assets/") - // projectFolder/assets - File assetsFolder = new File("${'$'}{project.rootDir}/assets/") - // projectFolder/assets/assets.txt - File assetsFile = new File(assetsFolder, "assets.txt") - // delete that file in case we've already created it - assetsFile.delete() - - // iterate through all files inside that folder - // convert it to a relative path - // and append it to the file assets.txt - fileTree(assetsFolder).collect { assetsFolder.relativePath(it) }.sort().each { - assetsFile.append(it + "\n") - } -} -processResources.dependsOn 'generateAssetList' - -compileJava { - options.incremental = true -}${if (project.rootGradle.plugins.contains("kotlin")) { - """ -compileKotlin.compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_${ - if (project.advanced.javaVersion.removePrefix("1.") == "8") { - "1_8" - } else { - project.advanced.javaVersion.removePrefix("1.") - }}) -""" - } else { - "" - }} - -[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' + return """[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' eclipse.project.name = appName + '-core' -java.sourceCompatibility = ${project.advanced.javaVersion} -java.targetCompatibility = ${project.advanced.javaVersion} - dependencies { ${joinDependencies(dependencies, "api")} if(enableGraalNative == 'true') { diff --git a/src/main/kotlin/gdx/liftoff/data/platforms/Lwjgl3.kt b/src/main/kotlin/gdx/liftoff/data/platforms/Lwjgl3.kt index 66c65f44..d6bcaa92 100644 --- a/src/main/kotlin/gdx/liftoff/data/platforms/Lwjgl3.kt +++ b/src/main/kotlin/gdx/liftoff/data/platforms/Lwjgl3.kt @@ -137,15 +137,17 @@ buildscript { gradlePluginPortal() } dependencies { + classpath "io.github.fourlastor:construo:1.4.2" if(enableGraalNative == 'true') { classpath "org.graalvm.buildtools.native:org.graalvm.buildtools.native.gradle.plugin:0.9.28" } } } plugins { - id "io.github.fourlastor.construo" version "1.4.1" id "application" -${if (project.rootGradle.plugins.contains("kotlin")) " id 'org.jetbrains.kotlin.jvm' version '${project.languages.getVersion("kotlin")}'\n" else ""}} +} +apply plugin: 'io.github.fourlastor.construo' +${if (project.rootGradle.plugins.contains("kotlin")) "apply plugin: 'org.jetbrains.kotlin.jvm'\n" else ""} import io.github.fourlastor.construo.Target