Skip to content

Commit

Permalink
Set JVM attribute on copied configuration (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Feb 20, 2023
1 parent 91a63f2 commit 3c2c268
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.gradle.api.artifacts.result.ResolvedArtifactResult
import org.gradle.api.attributes.Attribute
import org.gradle.api.attributes.HasConfigurableAttributes
import org.gradle.api.attributes.java.TargetJvmVersion;
import org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier
import org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependencyConstraint
import org.gradle.api.specs.Specs.SATISFIES_ALL
Expand Down Expand Up @@ -143,6 +144,8 @@ class Resolver(
addRevisionFilter(copy, revision)
addAttributes(copy, configuration)
addCustomResolutionStrategy(copy, currentCoordinates)

disableAutoTargetJvm(copy)
return copy
}

Expand Down Expand Up @@ -192,6 +195,12 @@ class Resolver(
return nonTransitiveDependency
}

private fun disableAutoTargetJvm(configuration: Configuration) {
// Disable the auto target jvm for the configuration
// https://github.com/ben-manes/gradle-versions-plugin/issues/727#issuecomment-1427132589
configuration.attributes.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, Integer.MAX_VALUE);
}

/** Adds the attributes from the source to the target. */
private fun addAttributes(
target: HasConfigurableAttributes<*>,
Expand Down Expand Up @@ -256,6 +265,7 @@ class Resolver(
val coordinates = hashMapOf<Coordinate.Key, Coordinate>()
val copy = configuration.copyRecursive().setTransitive(transitive)

disableAutoTargetJvm(copy)
val lenient = copy.resolvedConfiguration.lenientConfiguration

val resolved = lenient.getFirstLevelModuleDependencies(SATISFIES_ALL)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=com.github.ben-manes
VERSION_NAME=0.45.0
VERSION_NAME=0.46.0

POM_INCEPTION_YEAR=2012
POM_PACKAGING=jar
Expand Down

0 comments on commit 3c2c268

Please sign in to comment.