Skip to content

Commit

Permalink
Weirdest. Fix. Ever.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tommyettinger committed Oct 20, 2024
1 parent fc4dc31 commit e4b93a3
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 85 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
23 changes: 1 addition & 22 deletions src/main/kotlin/gdx/liftoff/data/files/ProjectFiles.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,7 @@ class SettingsFile(val platforms: Iterable<Platform>) : 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 """,
Expand Down
56 changes: 49 additions & 7 deletions src/main/kotlin/gdx/liftoff/data/files/gradle/RootGradleFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand All @@ -66,4 +104,8 @@ eclipse.project.name = '${project.basic.name}' + '-parent'
""
}}
}
*/
}
eclipse.project.name = '${project.basic.name}' + '-parent'
"""
}
1 change: 1 addition & 0 deletions src/main/kotlin/gdx/liftoff/data/languages/Kotlin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
14 changes: 8 additions & 6 deletions src/main/kotlin/gdx/liftoff/data/platforms/Android.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -208,6 +205,11 @@ android {
}}
}
repositories {
// needed for AAPT2, may be needed for other tools
google()
}
configurations { natives }
dependencies {
Expand Down
50 changes: 3 additions & 47 deletions src/main/kotlin/gdx/liftoff/data/platforms/Core.kt
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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) {
Expand All @@ -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') {
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/gdx/liftoff/data/platforms/Lwjgl3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e4b93a3

Please sign in to comment.