org.groovymc.modsdotgroovy.gradle.tasks.GatherLoomPlatformDetails.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-plugin Show documentation
Show all versions of gradle-plugin Show documentation
A Gradle plugin for creation of mods metadata file from a groovy file
The newest version!
package org.groovymc.modsdotgroovy.gradle.tasks
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.gradle.api.artifacts.component.ComponentArtifactIdentifier
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.jetbrains.annotations.Nullable
@CacheableTask
@CompileStatic
abstract class GatherLoomPlatformDetails extends AbstractGatherPlatformDetailsTask {
@Input
abstract ListProperty getArtifactIds()
@Input
abstract Property getTargetGroup()
@Input
abstract Property getTargetModule()
private String calculatePlatformVersion() {
return artifactIds.get().findResult {
def component = it.componentIdentifier
if (component instanceof ModuleComponentIdentifier) {
def module = component as ModuleComponentIdentifier
if (module.group == targetGroup.get() && module.module == targetModule.get()) {
return module.version
}
}
return null
}
}
GatherLoomPlatformDetails() {
// query loom after project evaluate instead of during a task run for the sake of better caching
this.minecraftVersion.convention(getMCVersionFromLoom())
}
@Override
void run() throws IllegalStateException {
@Nullable String minecraftVersion = this.minecraftVersion.getOrNull()
@Nullable String platformVersion = this.platformVersion.getOrNull() ?: calculatePlatformVersion()
this.writePlatformDetails(minecraftVersion, platformVersion)
}
@CompileDynamic
private Provider getMCVersionFromLoom() {
return project.provider {
final @Nullable def loomExtension = project.extensions.findByName('loom')
if (loomExtension?.hasProperty('minecraftVersion')) {
return (String) loomExtension.minecraftVersion.get()
}
return null
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy