Improve generate dev bundle task configuration cache compatibility
This commit removes storing `Project` as a task input or field and removes illegal method calls agains `Project` during task execution. Unfortunately this is still not actually configuration cache compatible as I haven't found a way to pass `ArtifactCollection` as a configuration cache compatible task input. Using `Configuration` directly works on first run, but Gradle is unable to load the configuration cache entry for that task input.
This commit is contained in:
parent
27957e759a
commit
bfa8e20ff8
4 changed files with 50 additions and 53 deletions
|
@ -153,9 +153,9 @@ class PaperweightCore : Plugin<Project> {
|
|||
) ?: return@afterEvaluate
|
||||
|
||||
devBundleTasks.configure(
|
||||
ext.serverProject.get(),
|
||||
ext.bundlerJarName.get(),
|
||||
ext.mainClass,
|
||||
ext.serverProject,
|
||||
ext.minecraftVersion,
|
||||
tasks.decompileJar.map { it.outputJar.path },
|
||||
tasks.extractFromBundler.map { it.serverLibrariesTxt.path },
|
||||
|
@ -174,6 +174,7 @@ class PaperweightCore : Plugin<Project> {
|
|||
)
|
||||
paramMappingsUrl.set(ext.paramMappingsRepo)
|
||||
}
|
||||
devBundleTasks.configureAfterEvaluate()
|
||||
|
||||
bundlerJarTasks.configureBundlerTasks(
|
||||
tasks.extractFromBundler.flatMap { it.versionJson },
|
||||
|
|
|
@ -32,6 +32,7 @@ import kotlin.io.path.*
|
|||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
|
||||
import org.gradle.api.file.RegularFile
|
||||
import org.gradle.api.plugins.JavaPlugin
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.TaskContainer
|
||||
|
@ -39,7 +40,7 @@ import org.gradle.kotlin.dsl.*
|
|||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
class DevBundleTasks(
|
||||
private val project: Project,
|
||||
project: Project,
|
||||
tasks: TaskContainer = project.tasks,
|
||||
) {
|
||||
val serverBundlerForDevBundle by tasks.registering<CreateBundlerJar> {
|
||||
|
@ -61,9 +62,9 @@ class DevBundleTasks(
|
|||
}
|
||||
|
||||
fun configure(
|
||||
serverProj: Project,
|
||||
bundlerJarName: String,
|
||||
mainClassName: Property<String>,
|
||||
serverProj: Provider<Project>,
|
||||
minecraftVer: Provider<String>,
|
||||
decompileJar: Provider<Path?>,
|
||||
serverLibrariesTxt: Provider<Path?>,
|
||||
|
@ -81,9 +82,7 @@ class DevBundleTasks(
|
|||
registerVersionArtifact(
|
||||
bundlerJarName,
|
||||
versionJsonFile,
|
||||
serverProj.flatMap { proj ->
|
||||
proj.tasks.named<FixJarForReobf>("fixJarForReobf").flatMap { it.inputJar }
|
||||
}
|
||||
serverProj.tasks.named<FixJarForReobf>("fixJarForReobf").flatMap { it.inputJar }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +93,7 @@ class DevBundleTasks(
|
|||
}
|
||||
|
||||
generateDevelopmentBundle {
|
||||
sourceDir.set(serverProj.map { it.layout.projectDirectory.dir("src/main/java") })
|
||||
sourceDir.set(serverProj.layout.projectDirectory.dir("src/main/java"))
|
||||
minecraftVersion.set(minecraftVer)
|
||||
mojangMappedPaperclipFile.set(paperclipForDevBundle.flatMap { it.outputZip })
|
||||
vanillaServerLibraries.set(
|
||||
|
@ -102,20 +101,21 @@ class DevBundleTasks(
|
|||
txt.readLines(Charsets.UTF_8).filter { it.isNotBlank() }
|
||||
}
|
||||
)
|
||||
serverProject.set(serverProj)
|
||||
relocations.set(serverProj.flatMap { proj -> proj.the<RelocationExtension>().relocations.map { gson.toJson(it) } })
|
||||
|
||||
serverVersion.set(serverProj.version.toString())
|
||||
serverCoordinates.set(GenerateDevBundle.createCoordinatesFor(serverProj))
|
||||
compileConfiguration.set(serverProj.configurations.named(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME))
|
||||
runtimeConfiguration.set(serverProj.configurations.named(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME))
|
||||
|
||||
relocations.set(serverProj.the<RelocationExtension>().relocations.map { gson.toJson(it) })
|
||||
decompiledJar.pathProvider(decompileJar)
|
||||
atFile.pathProvider(accessTransformFile)
|
||||
|
||||
devBundleConfiguration(this)
|
||||
}
|
||||
|
||||
project.afterEvaluate {
|
||||
configureAfterEvaluate()
|
||||
}
|
||||
}
|
||||
|
||||
private fun configureAfterEvaluate() {
|
||||
fun configureAfterEvaluate() {
|
||||
generateDevelopmentBundle {
|
||||
remapperUrl.set(project.repositories.named<MavenArtifactRepository>(REMAPPER_REPO_NAME).map { it.url.toString() })
|
||||
decompilerUrl.set(project.repositories.named<MavenArtifactRepository>(DECOMPILER_REPO_NAME).map { it.url.toString() })
|
||||
|
|
|
@ -32,24 +32,23 @@ import java.nio.charset.Charset
|
|||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
import kotlin.io.path.*
|
||||
import org.apache.tools.ant.types.selectors.SelectorUtils
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.artifacts.ExternalModuleDependency
|
||||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
|
||||
import org.gradle.api.artifacts.result.ResolvedArtifactResult
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.ProjectLayout
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.plugins.JavaPlugin
|
||||
import org.gradle.api.provider.ListProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Classpath
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputDirectory
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
|
@ -67,6 +66,12 @@ abstract class GenerateDevBundle : DefaultTask() {
|
|||
@get:InputFile
|
||||
abstract val mojangMappedPaperclipFile: RegularFileProperty
|
||||
|
||||
@get:Input
|
||||
abstract val serverVersion: Property<String>
|
||||
|
||||
@get:Input
|
||||
abstract val serverCoordinates: Property<String>
|
||||
|
||||
@get:Input
|
||||
abstract val apiCoordinates: Property<String>
|
||||
|
||||
|
@ -82,8 +87,11 @@ abstract class GenerateDevBundle : DefaultTask() {
|
|||
@get:Input
|
||||
abstract val libraryRepositories: ListProperty<String>
|
||||
|
||||
@get:Internal
|
||||
abstract val serverProject: Property<Project>
|
||||
@get:Classpath
|
||||
abstract val compileConfiguration: Property<Configuration>
|
||||
|
||||
@get:Classpath
|
||||
abstract val runtimeConfiguration: Property<Configuration>
|
||||
|
||||
@get:Input
|
||||
abstract val relocations: Property<String>
|
||||
|
@ -115,6 +123,9 @@ abstract class GenerateDevBundle : DefaultTask() {
|
|||
@get:OutputFile
|
||||
abstract val devBundleFile: RegularFileProperty
|
||||
|
||||
@get:Inject
|
||||
abstract val layout: ProjectLayout
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val devBundle = devBundleFile.path
|
||||
|
@ -150,7 +161,7 @@ abstract class GenerateDevBundle : DefaultTask() {
|
|||
}
|
||||
|
||||
private fun generatePatches(output: Path) {
|
||||
val workingDir = project.layout.cache.resolve(paperTaskOutput("tmpdir"))
|
||||
val workingDir = layout.cache.resolve(paperTaskOutput("tmpdir"))
|
||||
workingDir.createDirectories()
|
||||
sourceDir.path.copyRecursivelyTo(workingDir)
|
||||
|
||||
|
@ -287,9 +298,9 @@ abstract class GenerateDevBundle : DefaultTask() {
|
|||
private fun createBundleConfig(dataTargetDir: String, patchTargetDir: String): DevBundleConfig {
|
||||
return DevBundleConfig(
|
||||
minecraftVersion = minecraftVersion.get(),
|
||||
mappedServerCoordinates = createCoordinatesFor(serverProject.get()),
|
||||
apiCoordinates = "${apiCoordinates.get()}:${serverProject.get().version}",
|
||||
mojangApiCoordinates = "${mojangApiCoordinates.get()}:${serverProject.get().version}",
|
||||
mappedServerCoordinates = serverCoordinates.get(),
|
||||
apiCoordinates = "${apiCoordinates.get()}:$serverVersion",
|
||||
mojangApiCoordinates = "${mojangApiCoordinates.get()}:$serverVersion",
|
||||
buildData = createBuildDataConfig(dataTargetDir),
|
||||
decompile = createDecompileRunner(),
|
||||
remapper = createRemapDep(),
|
||||
|
@ -297,9 +308,6 @@ abstract class GenerateDevBundle : DefaultTask() {
|
|||
)
|
||||
}
|
||||
|
||||
private fun createCoordinatesFor(project: Project): String =
|
||||
sequenceOf(project.group, project.name.toLowerCase(Locale.ENGLISH), "userdev-" + project.version).joinToString(":")
|
||||
|
||||
private fun relocations(): List<Relocation> = gson.fromJson(relocations.get())
|
||||
|
||||
private fun createBuildDataConfig(targetDir: String): BuildData {
|
||||
|
@ -309,8 +317,8 @@ abstract class GenerateDevBundle : DefaultTask() {
|
|||
accessTransformFile = "$targetDir/$atFileName",
|
||||
mojangMappedPaperclipFile = "$targetDir/$mojangMappedPaperclipFileName",
|
||||
vanillaJarIncludes = vanillaJarIncludes.get(),
|
||||
compileDependencies = determineLibraries(serverProject.get(), vanillaServerLibraries.get()).sorted(),
|
||||
runtimeDependencies = collectRuntimeDependencies(serverProject.get()).map { it.coordinates }.sorted(),
|
||||
compileDependencies = determineLibraries(vanillaServerLibraries.get()).sorted(),
|
||||
runtimeDependencies = collectRuntimeDependencies().map { it.coordinates }.sorted(),
|
||||
libraryRepositories = libraryRepositories.get(),
|
||||
relocations = relocations(),
|
||||
minecraftRemapArgs = TinyRemapper.minecraftRemapArgs,
|
||||
|
@ -318,25 +326,12 @@ abstract class GenerateDevBundle : DefaultTask() {
|
|||
)
|
||||
}
|
||||
|
||||
private fun determineLibraries(serverProject: Project, vanillaServerLibraries: List<String>): Set<String> {
|
||||
val new = arrayListOf<ModuleId>()
|
||||
|
||||
for (dependency in serverProject.configurations.named(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME).get().dependencies) {
|
||||
// don't want project dependencies
|
||||
if (dependency is ExternalModuleDependency) {
|
||||
val version = sequenceOf(
|
||||
dependency.versionConstraint.strictVersion,
|
||||
dependency.versionConstraint.requiredVersion,
|
||||
dependency.versionConstraint.preferredVersion,
|
||||
dependency.version
|
||||
).filterNotNull().filter { it.isNotBlank() }.first()
|
||||
new += ModuleId(
|
||||
dependency.group,
|
||||
dependency.name,
|
||||
version
|
||||
)
|
||||
private fun determineLibraries(vanillaServerLibraries: List<String>): Set<String> {
|
||||
val new: MutableList<ModuleId> = compileConfiguration.get().incoming.artifacts.artifacts
|
||||
.mapNotNullTo(ArrayList()) {
|
||||
val module = it.id.componentIdentifier as? ModuleComponentIdentifier ?: return@mapNotNullTo null
|
||||
ModuleId.fromIdentifier(module)
|
||||
}
|
||||
}
|
||||
|
||||
for (vanillaLib in vanillaServerLibraries) {
|
||||
val vanilla = ModuleId.parse(vanillaLib)
|
||||
|
@ -357,12 +352,9 @@ abstract class GenerateDevBundle : DefaultTask() {
|
|||
private val ResolvedArtifactResult.coordinates: String
|
||||
get() = ModuleId.fromIdentifier(id.componentIdentifier as ModuleComponentIdentifier).toString()
|
||||
|
||||
private fun collectRuntimeDependencies(
|
||||
serverProject: Project
|
||||
): Set<ResolvedArtifactResult> = serverProject.configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)
|
||||
.incoming.artifacts.artifacts.filterTo(HashSet()) {
|
||||
val id = it.id.componentIdentifier
|
||||
id is ModuleComponentIdentifier
|
||||
private fun collectRuntimeDependencies(): Set<ResolvedArtifactResult> =
|
||||
runtimeConfiguration.get().incoming.artifacts.artifacts.filterTo(HashSet()) {
|
||||
it.id.componentIdentifier is ModuleComponentIdentifier
|
||||
}
|
||||
|
||||
private fun createDecompileRunner(): Runner {
|
||||
|
@ -409,5 +401,8 @@ abstract class GenerateDevBundle : DefaultTask() {
|
|||
|
||||
// Should be bumped when the dev bundle config/contents changes in a way which will require users to update paperweight
|
||||
const val currentDataVersion = 3
|
||||
|
||||
fun createCoordinatesFor(project: Project): String =
|
||||
sequenceOf(project.group, project.name.toLowerCase(Locale.ENGLISH), "userdev-" + project.version).joinToString(":")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,9 +169,9 @@ class PaperweightPatcher : Plugin<Project> {
|
|||
}
|
||||
|
||||
devBundleTasks.configure(
|
||||
patcher.serverProject.get(),
|
||||
patcher.bundlerJarName.get(),
|
||||
patcher.mainClass,
|
||||
patcher.serverProject,
|
||||
upstreamData.map { it.mcVersion },
|
||||
upstreamData.map { it.decompiledJar },
|
||||
upstreamData.map { it.serverLibrariesTxt },
|
||||
|
@ -186,6 +186,7 @@ class PaperweightPatcher : Plugin<Project> {
|
|||
paramMappingsCoordinates.set(upstreamData.map { it.paramMappings.coordinates.single() })
|
||||
paramMappingsUrl.set(upstreamData.map { it.paramMappings.url })
|
||||
}
|
||||
devBundleTasks.configureAfterEvaluate()
|
||||
|
||||
val (_, reobfJar) = serverProj.setupServerProject(
|
||||
target,
|
||||
|
|
Loading…
Reference in a new issue