Skip to content

Commit

Permalink
Adjust spigot dependency download for Gradle 8.11+
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Dec 3, 2024
1 parent a869b9e commit 64aeed7
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import javax.inject.Inject
import javax.xml.parsers.DocumentBuilderFactory
import kotlin.io.path.*
import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.component.ComponentIdentifier
import org.gradle.api.artifacts.dsl.DependencyFactory
import org.gradle.api.attributes.java.TargetJvmEnvironment
Expand Down Expand Up @@ -202,11 +203,7 @@ abstract class DownloadSpigotDependencies : BaseTask() {
for (repo in spigotRepos) {
resolver.repositories.maven(repo)
}
val config = resolver.configurations.create("spigotDependencies") {
attributes {
attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment.STANDARD_JVM))
}
}
val deps = mutableListOf<Dependency>()
for (artifact in artifacts) {
val gav = artifact.gav.let {
if (it == "com.google.guava:guava:32.1.2-jre") {
Expand All @@ -216,7 +213,7 @@ abstract class DownloadSpigotDependencies : BaseTask() {
it
}
}
config.dependencies.add(
deps.add(
dependencyFactory.create(gav).also {
it.artifact {
artifact.classifier?.let { s -> classifier = s }
Expand All @@ -226,6 +223,11 @@ abstract class DownloadSpigotDependencies : BaseTask() {
)
}

val config = resolver.configurations.detachedConfiguration(*deps.toTypedArray())
config.attributes {
attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment.STANDARD_JVM))
}

// The source variants don't have transitives
val flatComponents = mutableSetOf<ComponentIdentifier>()

Expand All @@ -234,28 +236,28 @@ abstract class DownloadSpigotDependencies : BaseTask() {
flatComponents += artifact.id.componentIdentifier
}

val sourcesConfig = resolver.configurations.create("spigotDependenciesSources") {
attributes {
// Mojang libs & Guava don't resolve metadata correctly, so we set the classifier below instead...

// attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
// attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType.SOURCES))
// attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
// attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))

// Needed since we set the classifier instead of using above attributes
attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment.STANDARD_JVM))
}
}
val sourcesDeps = mutableListOf<Dependency>()
for (component in flatComponents) {
sourcesConfig.dependencies.add(
sourcesDeps.add(
dependencyFactory.create(component.displayName).also {
it.artifact {
classifier = "sources"
}
}
)
}
val sourcesConfig = resolver.configurations.detachedConfiguration(*sourcesDeps.toTypedArray())
sourcesConfig.attributes {
// Mojang libs & Guava don't resolve metadata correctly, so we set the classifier below instead...

// attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
// attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType.SOURCES))
// attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
// attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))

// Needed since we set the classifier instead of using above attributes
attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment.STANDARD_JVM))
}
val sourcesView = sourcesConfig.incoming.artifactView {
componentFilter {
mcLibraries.none { l -> l == it.displayName } &&
Expand Down

0 comments on commit 64aeed7

Please sign in to comment.