Skip to content

Commit

Permalink
Fix exclusion handling when a platform depends on a platform
Browse files Browse the repository at this point in the history
See gh-360
  • Loading branch information
wilkinsona committed Jul 13, 2023
1 parent b36e4a0 commit d34453b
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ private Set<DependencyCandidate> findExcludedDependencies() {
resolutionResult.allDependencies((dependencyResult) -> {
if (dependencyResult instanceof ResolvedDependencyResult) {
ResolvedDependencyResult resolved = (ResolvedDependencyResult) dependencyResult;
excludedDependencies.add(new DependencyCandidate(resolved.getSelected().getModuleVersion()));
if (!isPlatform(resolved.getSelected())) {
excludedDependencies.add(new DependencyCandidate(resolved.getSelected().getModuleVersion()));
}
}
else if (dependencyResult instanceof UnresolvedDependencyResult) {
DependencyCandidate dependencyCandidate = toDependencyCandidate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,8 @@ void resolutionSucceedsWhenDependencyReliesOnDependencyManagementFromItsAncestor
@Test
void resolutionSucceedsWhenDependencyReliesOnConstraintsFromPlatformDependencies() {
this.gradleBuild.runner().withArguments("resolve").build();
assertThat(readLines("resolved.txt")).containsExactly("guava-32.1.1-jre.jar", "failureaccess-1.0.1.jar",
"jsr305-3.0.2.jar", "checker-qual-3.33.0.jar", "error_prone_annotations-2.18.0.jar",
"j2objc-annotations-2.8.jar");
assertThat(readLines("resolved.txt")).containsExactly("platform-consumer-1.0.jar", "spring-core-5.3.27.jar",
"spring-jcl-5.3.27.jar");
}

private void writeLines(Path path, String... lines) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ plugins {
}

repositories {
maven {
url file("maven-repo")
}
mavenCentral()
}

dependencies {
implementation("com.google.guava:guava:32.1.1-jre");
implementation("test:platform-consumer:1.0");
}

tasks.register("resolve") {
doFirst {
def files = project.configurations.compileClasspath.resolve()
def files = project.configurations.runtimeClasspath.resolve()
def output = new File("${buildDir}/resolved.txt")
output.parentFile.mkdirs()
files.collect { it.name }.each { output << "${it}\n" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"formatVersion": "1.1",
"component": {
"group": "test",
"module": "platform-a",
"version": "1.0",
"attributes": {
"org.gradle.status": "release"
}
},
"createdBy": {
"gradle": {
"version": "8.1.1"
}
},
"variants": [
{
"name": "apiElements",
"attributes": {
"org.gradle.category": "platform",
"org.gradle.usage": "java-api"
},
"dependencyConstraints": [
{
"group": "org.springframework",
"module": "spring-core",
"version": {
"requires": "5.3.27"
}
}
]
},
{
"name": "runtimeElements",
"attributes": {
"org.gradle.category": "platform",
"org.gradle.usage": "java-runtime"
},
"dependencyConstraints": [
{
"group": "org.springframework",
"module": "spring-core",
"version": {
"requires": "5.3.27"
}
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
<!-- is to indicate to Gradle or any Gradle module metadata file consumer -->
<!-- that they should prefer consuming it instead. -->
<!-- do_not_remove: published-with-gradle-metadata -->
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>platform-a</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.27</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"formatVersion": "1.1",
"component": {
"group": "test",
"module": "platform-b",
"version": "1.0",
"attributes": {
"org.gradle.status": "release"
}
},
"createdBy": {
"gradle": {
"version": "8.1.1"
}
},
"variants": [
{
"name": "apiElements",
"attributes": {
"org.gradle.category": "platform",
"org.gradle.usage": "java-api"
},
"dependencies": [
{
"group": "test",
"module": "platform-a",
"version": {
"requires": "1.0"
},
"attributes": {
"org.gradle.category": "platform"
},
"endorseStrictVersions": true
}
]
},
{
"name": "runtimeElements",
"attributes": {
"org.gradle.category": "platform",
"org.gradle.usage": "java-runtime"
},
"dependencies": [
{
"group": "test",
"module": "platform-a",
"version": {
"requires": "1.0"
},
"attributes": {
"org.gradle.category": "platform"
},
"endorseStrictVersions": true
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
<!-- is to indicate to Gradle or any Gradle module metadata file consumer -->
<!-- that they should prefer consuming it instead. -->
<!-- do_not_remove: published-with-gradle-metadata -->
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>platform-b</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>platform-a</artifactId>
<version>1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"formatVersion": "1.1",
"component": {
"group": "test",
"module": "platform-consumer",
"version": "1.0",
"attributes": {
"org.gradle.status": "release"
}
},
"createdBy": {
"gradle": {
"version": "8.1.1"
}
},
"variants": [
{
"name": "apiElements",
"attributes": {
"org.gradle.category": "library",
"org.gradle.dependency.bundling": "external",
"org.gradle.jvm.version": 8,
"org.gradle.libraryelements": "jar",
"org.gradle.usage": "java-api"
},
"files": [
{
"name": "platform-consumer-1.0.jar",
"url": "platform-consumer-1.0.jar",
"size": 261,
"sha512": "86a5a26d8dc2dfe3e97ea8f8761a35cabe6b01025519f5427fe99b1709ca62f78b4e29a8e400b960135bc5fad3ea72fe96a04c3ebf7598ace72933c14e56a954",
"sha256": "800949e7d33f8be22c0a11bbffb097a9035ab490b106da8918a9dee8d7ba99b1",
"sha1": "61157ea5caf7ebdfba10833bfbb55eebd4c12a6d",
"md5": "82d43140d8833264c949d20116b4d8bd"
}
]
},
{
"name": "runtimeElements",
"attributes": {
"org.gradle.category": "library",
"org.gradle.dependency.bundling": "external",
"org.gradle.jvm.version": 8,
"org.gradle.libraryelements": "jar",
"org.gradle.usage": "java-runtime"
},
"dependencies": [
{
"group": "test",
"module": "platform-b",
"version": {
"requires": "1.0"
},
"attributes": {
"org.gradle.category": "platform"
},
"endorseStrictVersions": true
},
{
"group": "org.springframework",
"module": "spring-core"
}
],
"files": [
{
"name": "platform-consumer-1.0.jar",
"url": "platform-consumer-1.0.jar",
"size": 261,
"sha512": "86a5a26d8dc2dfe3e97ea8f8761a35cabe6b01025519f5427fe99b1709ca62f78b4e29a8e400b960135bc5fad3ea72fe96a04c3ebf7598ace72933c14e56a954",
"sha256": "800949e7d33f8be22c0a11bbffb097a9035ab490b106da8918a9dee8d7ba99b1",
"sha1": "61157ea5caf7ebdfba10833bfbb55eebd4c12a6d",
"md5": "82d43140d8833264c949d20116b4d8bd"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
<!-- is to indicate to Gradle or any Gradle module metadata file consumer -->
<!-- that they should prefer consuming it instead. -->
<!-- do_not_remove: published-with-gradle-metadata -->
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>platform-consumer</artifactId>
<version>1.0</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>platform-b</artifactId>
<version>1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>

0 comments on commit d34453b

Please sign in to comment.