userdev: add mojangMappedServerRuntime configuration and deprecate PaperweightUserExtension#mojangMappedServerJar

This commit is contained in:
Jason Penilla 2021-11-28 21:09:30 -08:00
parent 8d47aaa469
commit 777d41fc69
No known key found for this signature in database
GPG key ID: 0E75A301420E48F8
5 changed files with 67 additions and 10 deletions

View file

@ -37,6 +37,8 @@ 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.RegularFileProperty
import org.gradle.api.plugins.JavaPlugin
@ -306,7 +308,8 @@ abstract class GenerateDevBundle : DefaultTask() {
accessTransformFile = "$targetDir/$atFileName",
mojangMappedPaperclipFile = "$targetDir/$mojangMappedPaperclipFileName",
vanillaJarIncludes = vanillaJarIncludes.get(),
libraryDependencies = determineLibraries(serverProject.get(), vanillaServerLibraries.get()),
compileDependencies = determineLibraries(serverProject.get(), vanillaServerLibraries.get()).sorted(),
runtimeDependencies = collectRuntimeDependencies(serverProject.get()).map { it.coordinates }.sorted(),
libraryRepositories = libraryRepositories.get(),
relocations = relocations(),
minecraftRemapArgs = TinyRemapper.minecraftRemapArgs,
@ -315,7 +318,7 @@ abstract class GenerateDevBundle : DefaultTask() {
}
private fun determineLibraries(serverProject: Project, vanillaServerLibraries: List<String>): Set<String> {
val new = arrayListOf<String>()
val new = arrayListOf<Triple<String, String, String>>()
for (dependency in serverProject.configurations.named(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME).get().dependencies) {
// don't want project dependencies
@ -326,16 +329,22 @@ abstract class GenerateDevBundle : DefaultTask() {
dependency.versionConstraint.preferredVersion,
dependency.version
).filterNotNull().filter { it.isNotBlank() }.first()
new += sequenceOf(
new += Triple(
dependency.group,
dependency.name,
version
).joinToString(":")
)
}
}
val result = vanillaServerLibraries.toMutableSet()
result += new
for (vanillaLib in vanillaServerLibraries) {
val (group, name, version) = vanillaLib.split(":")
if (new.none { it.first == group && it.second == name }) {
new += Triple(group, name, version)
}
}
val result = new.map { "${it.first}:${it.second}:${it.third}" }.toMutableSet()
// Remove relocated libraries
val libs = relocations().mapNotNull { it.owningLibraryCoordinates }
@ -344,6 +353,20 @@ abstract class GenerateDevBundle : DefaultTask() {
return result
}
private val ResolvedArtifactResult.coordinates: String
get() {
val id = (id.componentIdentifier as ModuleComponentIdentifier)
return "${id.group}:${id.module}:${id.version}"
}
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 createDecompileRunner(): Runner {
return Runner(
dep = determineMavenDep(decompilerUrl, decompilerConfig),
@ -371,7 +394,8 @@ abstract class GenerateDevBundle : DefaultTask() {
val accessTransformFile: String,
val mojangMappedPaperclipFile: String,
val vanillaJarIncludes: List<String>,
val libraryDependencies: Set<String>,
val compileDependencies: List<String>,
val runtimeDependencies: List<String>,
val libraryRepositories: List<String>,
val relocations: List<Relocation>,
val minecraftRemapArgs: List<String>,

View file

@ -39,6 +39,7 @@ const val DECOMPILER_CONFIG = "decompiler"
const val PAPERCLIP_CONFIG = "paperclip"
const val DEV_BUNDLE_CONFIG = "paperweightDevelopmentBundle"
const val MOJANG_MAPPED_SERVER_CONFIG = "mojangMappedServer"
const val MOJANG_MAPPED_SERVER_RUNTIME_CONFIG = "mojangMappedServerRuntime"
const val REOBF_CONFIG = "reobf"
const val PARAM_MAPPINGS_REPO_NAME = "paperweightParamMappingsRepository"

View file

@ -32,6 +32,7 @@ import io.papermc.paperweight.util.constants.*
import javax.inject.Inject
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.ExternalModuleDependency
import org.gradle.api.attributes.Bundling
import org.gradle.api.attributes.Category
import org.gradle.api.attributes.LibraryElements
@ -232,7 +233,7 @@ abstract class PaperweightUser : Plugin<Project> {
}
}
target.configurations.create(MOJANG_MAPPED_SERVER_CONFIG) {
val mojangMappedServerConfig = target.configurations.create(MOJANG_MAPPED_SERVER_CONFIG) {
exclude("junit", "junit") // json-simple exposes junit for some reason
defaultDependencies {
userdevSetup.get().createOrUpdateIvyRepository(
@ -248,7 +249,33 @@ abstract class PaperweightUser : Plugin<Project> {
JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME
).map(target.configurations::named).forEach { config ->
config {
extendsFrom(target.configurations.getByName(MOJANG_MAPPED_SERVER_CONFIG))
extendsFrom(mojangMappedServerConfig)
}
}
}
target.configurations.create(MOJANG_MAPPED_SERVER_RUNTIME_CONFIG) {
defaultDependencies {
userdevSetup.get().createOrUpdateIvyRepository(
UserdevSetup.Context(target, workerExecutor, javaToolchainService)
)
listOf(
devBundleConfig.mappedServerCoordinates,
devBundleConfig.apiCoordinates,
devBundleConfig.mojangApiCoordinates
).forEach { coordinate ->
val dep = target.dependencies.create(coordinate).also {
(it as ExternalModuleDependency).isTransitive = false
}
add(dep)
}
for (coordinates in userdevSetup.get().devBundleConfig.buildData.runtimeDependencies) {
val dep = target.dependencies.create(coordinates).also {
(it as ExternalModuleDependency).isTransitive = false
}
add(dep)
}
}
}

View file

@ -53,6 +53,11 @@ abstract class PaperweightUserExtension(
/**
* Provides a runnable Mojang mapped server jar, extracted from the current dev bundle.
*/
@Deprecated(
message = "As of 1.18, the dev bundle no longer contains a runnable server jar. Use the mojangMappedServerRuntime configuration instead.",
replaceWith = ReplaceWith("project.configurations.mojangMappedServerRuntime"),
level = DeprecationLevel.WARNING
)
val mojangMappedServerJar: Provider<RegularFile> = objects.fileProperty().pathProvider(
setup.map {
it.applyMojangMappedPaperclipPatch(

View file

@ -390,7 +390,7 @@ abstract class UserdevSetup : BuildService<UserdevSetup.Parameters> {
val didInstall = installToIvyRepo(
cache.resolve(IVY_REPOSITORY),
devBundleConfig.mappedServerCoordinates,
devBundleConfig.buildData.libraryDependencies.toList() +
devBundleConfig.buildData.compileDependencies.toList() +
devBundleConfig.apiCoordinates +
devBundleConfig.mojangApiCoordinates,
patchedSourcesJar,