87 lines
2.7 KiB
Groovy
87 lines
2.7 KiB
Groovy
apply plugin: "java"
|
|
|
|
version '1.0'
|
|
|
|
targetCompatibility = 8
|
|
//switch to JavaVersion.VERSION_17 to use Java 17 features; this requires adding jabel (see dependencies block below)
|
|
sourceCompatibility = 8
|
|
|
|
sourceSets.main.java.srcDirs = ["src"]
|
|
|
|
repositories{
|
|
mavenCentral()
|
|
maven{ url 'https://www.jitpack.io' }
|
|
}
|
|
|
|
ext{
|
|
//the build number that this mod is made for
|
|
mindustryVersion = 'v131'
|
|
jabelVersion = "0.7.0"
|
|
sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
|
|
}
|
|
|
|
//java 8 backwards compatibility flag
|
|
allprojects{
|
|
tasks.withType(JavaCompile){
|
|
options.compilerArgs.addAll(['--release', '8'])
|
|
}
|
|
}
|
|
|
|
dependencies{
|
|
compileOnly "com.github.Anuken.Arc:arc-core:$mindustryVersion"
|
|
compileOnly "com.github.Anuken.Mindustry:core:$mindustryVersion"
|
|
|
|
//you may uncomment this dependency to properly use Java 17 features while still targeting Java 8.
|
|
//note that this fails on some systems for as-of-yet unknown reasons - if this happens to you, revert the changes
|
|
//annotationProcessor "com.github.Anuken:jabel:$jabelVersion"
|
|
}
|
|
|
|
task jarAndroid{
|
|
dependsOn "jar"
|
|
|
|
doLast{
|
|
if(!sdkRoot || !new File(sdkRoot).exists()) throw new GradleException("No valid Android SDK found. Ensure that ANDROID_HOME is set to your Android SDK directory.");
|
|
|
|
def platformRoot = new File("$sdkRoot/platforms/").listFiles().sort().reverse().find{ f -> new File(f, "android.jar").exists()}
|
|
|
|
if(!platformRoot) throw new GradleException("No android.jar found. Ensure that you have an Android platform installed.")
|
|
|
|
//collect dependencies needed for desugaring
|
|
def dependencies = (configurations.compileClasspath.asList() + configurations.runtimeClasspath.asList() + [new File(platformRoot, "android.jar")]).collect{ "--classpath $it.path" }.join(" ")
|
|
|
|
//dex and desugar files - this requires d8 in your PATH
|
|
"d8 $dependencies --min-api 14 --output ${project.archivesBaseName}Android.jar ${project.archivesBaseName}Desktop.jar"
|
|
.execute(null, new File("$buildDir/libs")).waitForProcessOutput(System.out, System.err)
|
|
}
|
|
}
|
|
|
|
jar {
|
|
archiveFileName = "${project.archivesBaseName}Desktop.jar"
|
|
|
|
from {
|
|
configurations.runtimeClasspath.collect{ it.isDirectory() ? it : zipTree(it) }
|
|
}
|
|
|
|
from(rootDir) {
|
|
include "mod.json"
|
|
}
|
|
|
|
from("assets/") {
|
|
include "**"
|
|
}
|
|
}
|
|
|
|
task deploy(type: Jar){
|
|
dependsOn jarAndroid
|
|
dependsOn jar
|
|
archiveFileName = "${project.archivesBaseName}.jar"
|
|
|
|
from{ [zipTree("$buildDir/libs/${project.archivesBaseName}Desktop.jar"), zipTree("$buildDir/libs/${project.archivesBaseName}Android.jar")] }
|
|
|
|
doLast{
|
|
delete{
|
|
delete "$buildDir/libs/${project.archivesBaseName}Desktop.jar"
|
|
delete "$buildDir/libs/${project.archivesBaseName}Android.jar"
|
|
}
|
|
}
|
|
}
|