Skip to content

Commit

Permalink
Thanks again, Daniele!
Browse files Browse the repository at this point in the history
The build is now mostly working for Android Kotlin projects. It does print a long warning every time you do anything, and I'll see what I can do about that.
  • Loading branch information
tommyettinger committed Oct 19, 2024
1 parent e03473a commit 49532a5
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 63 deletions.
23 changes: 22 additions & 1 deletion src/main/kotlin/gdx/liftoff/data/files/ProjectFiles.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,28 @@ class SettingsFile(val platforms: Iterable<Platform>) : ProjectFile {
override fun save(destination: FileHandle) {
val content = platforms.joinToString(
prefix =
"""// A list of which subprojects to load as part of the same larger project.
"""
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.
// 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: 7 additions & 49 deletions src/main/kotlin/gdx/liftoff/data/files/gradle/RootGradleFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,53 +43,15 @@ 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 @@ -104,8 +66,4 @@ subprojects {
""
}}
}
}
eclipse.project.name = '${project.basic.name}' + '-parent'
"""
}
*/
1 change: 0 additions & 1 deletion src/main/kotlin/gdx/liftoff/data/languages/Kotlin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ 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
10 changes: 3 additions & 7 deletions src/main/kotlin/gdx/liftoff/data/platforms/Android.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ buildscript {
classpath 'com.android.tools.build:gradle:8.5.2'
}
}
${plugins.joinToString(separator = "\n") { "apply plugin: '$it'" }}
${if (latePlugin)"apply plugin: \'kotlin-android\'" else ""}
plugins {
id "com.android.application" version "8.4.2"
${if (latePlugin) " id 'org.jetbrains.kotlin.android' version '2.0.21'\n" else ""}}
android {
namespace "${project.basic.rootPackage}"
Expand Down Expand Up @@ -207,11 +208,6 @@ android {
}}
}
repositories {
// needed for AAPT2, may be needed for other tools
google()
}
configurations { natives }
dependencies {
Expand Down
48 changes: 45 additions & 3 deletions src/main/kotlin/gdx/liftoff/data/platforms/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Core : Platform {
override val order = ORDER
override val isStandard = false
override fun createGradleFile(project: Project): GradleFile {
return CoreGradleFile()
return CoreGradleFile(project)
}

override fun initiate(project: Project) {
Expand All @@ -31,15 +31,57 @@ class Core : Platform {
/**
* Gradle file of the core project. Should contain all multi-platform dependencies, like "gdx" itself.
*/
class CoreGradleFile : GradleFile(Core.ID) {
class CoreGradleFile(val project: Project) : GradleFile(Core.ID) {
init {
addDependency("com.badlogicgames.gdx:gdx:\$gdxVersion")
}

override fun getContent(): String {
return """[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
return """
plugins {
id "java-library"
${if ( project.rootGradle.plugins.contains("kotlin")) " id 'org.jetbrains.kotlin.jvm' version '2.0.21'\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'
eclipse.project.name = appName + '-core'
sourceCompatibility = ${project.advanced.javaVersion}
dependencies {
${joinDependencies(dependencies, "api")}
if(enableGraalNative == 'true') {
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/gdx/liftoff/data/platforms/Lwjgl3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ buildscript {
plugins {
id "io.github.fourlastor.construo" version "1.4.1"
id "application"
}
${if (project.rootGradle.plugins.contains("kotlin")) "apply plugin: 'org.jetbrains.kotlin.jvm'\n" else ""}
${if (project.rootGradle.plugins.contains("kotlin")) " id 'org.jetbrains.kotlin.jvm' version '2.0.21'\n" else ""}}
import io.github.fourlastor.construo.Target
Expand Down

0 comments on commit 49532a5

Please sign in to comment.