I’m wanting to dynamically generate the version appended to a jar. I made a custom task for this (SemverTask) and made compileJava depend on it. It creates the jar with the right version number, but future tasks act as if the version was never set. Am I doing something wrong? Here is my build.gradle
:
plugins {
id 'fabric-loom' version '0.5-SNAPSHOT'
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
archivesBaseName = project.archives_base_name
//version = project.mod_version
group = project.maven_group
// ...
// Generates the version number.
class SemverTask extends DefaultTask {
@Input
String baseVersion;
@TaskAction
def calculate() {
// ...
String nextVersion = """${lastVersion[0]}.${lastVersion[1]}.${lastVersion[2] + 1}""";
println("::set-output value=" + nextVersion);
project.setVersion(nextVersion);
}
def toIntArray(String[] strArr) {
int[] intArr = new int[strArr.length];
for (int i = 0; i < strArr.length; i++)
intArr[i] = strArr[i] as Integer;
return intArr;
}
}
task semver(type: SemverTask) {
baseVersion = project.mod_version
}
tasks.compileJava.dependsOn(semver);
tasks.withType(JavaCompile).configureEach {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
// We'll use that if it's available, but otherwise we'll use the older option.
def targetVersion = 8
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = targetVersion
}
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}
// ...
Here is the error I get:
> Task :semver
::set-output value=1.1.1
> Task :remapJar FAILED
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':remapJar' (type 'RemapJarTask').
> File 'C:\Users\<user>\Documents\MinecraftFabric\Corntopia\build\libs\corntopia-dev.jar' specified for property 'input' does not exist.
I tried setting project.version
, calling project.setProperty
or project.getProperties().put
but nothing changed the result in a meaningful way. It either output that error or it does not add a version at all. Tried asking on the Fabric Discord server (for the fabric-loom
dependency, which adds the remapJar task). Also have been searching online for roughly 3-6 hours now. Any help would be greatly appreciated!