Tasks not recieving version

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!

Still trying to narrow down what the problem is.

I found the remap task source code at: https://github.com/FabricMC/fabric-loom/blob/dd68c84226443013d3a6a2c62a438304f92b15d4/src/main/java/net/fabricmc/loom/task/RemapJarTask.java

The task is registered with the project tasks with a group and description. It then gets the input file from getProject().objects.fileProperty. But how does the property get set? It does not depend on anything and I never set it. It appears to be set to jarTask.getArchivePath().

Found the problem, appears I was setting version too late. The fabric-loom plugin is applied before any tasks are run, at which point it calls getArchiveVersion().

To solve this I ended up making my Semver.calculate() function static along with all of its dependencies and setting version initially to version = Semver.calculate().