Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/main/scala/bloop/integrations/maven/MojoImplementation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,18 @@ object MojoImplementation {
val resolution = Some(Config.Resolution(modules))

val (classpath, runtimeClasspath) = {
// keys of artifacts that survived Maven's exclusion resolution for this module.
val resolvedArtifactKeys: Set[String] = project.getArtifacts.asScala
.map(a => ArtifactUtils.versionlessKey(a))
.toSet

val projectDependencies = dependencies.flatMap { d =>
val build = d.getBuild()
if (configuration == "compile") build.getOutputDirectory() :: Nil
else build.getTestOutputDirectory() :: build.getOutputDirectory() :: Nil
if (!resolvedArtifactKeys.contains(ArtifactUtils.versionlessKey(d.getArtifact))) Nil
else {
val build = d.getBuild()
if (configuration == "compile") build.getOutputDirectory() :: Nil
else build.getTestOutputDirectory() :: build.getOutputDirectory() :: Nil
}
}

val cp = classpath0().asScala.toList.asInstanceOf[List[String]].map(u => abs(new File(u)))
Expand Down
17 changes: 17 additions & 0 deletions src/test/resources/exclusion/api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>exclusion</artifactId>
<version>0.1</version>
</parent>
<artifactId>api</artifactId>

<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>shims</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
</project>
23 changes: 23 additions & 0 deletions src/test/resources/exclusion/consumer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>exclusion</artifactId>
<version>0.1</version>
</parent>
<artifactId>consumer</artifactId>

<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>api</artifactId>
<version>0.1</version>
<exclusions>
<exclusion>
<groupId>com.example</groupId>
<artifactId>shims</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
13 changes: 13 additions & 0 deletions src/test/resources/exclusion/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>exclusion</artifactId>
<version>0.1</version>
<packaging>pom</packaging>

<modules>
<module>shims</module>
<module>api</module>
<module>consumer</module>
</modules>
</project>
9 changes: 9 additions & 0 deletions src/test/resources/exclusion/shims/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>exclusion</artifactId>
<version>0.1</version>
</parent>
<artifactId>shims</artifactId>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,39 @@ class MavenConfigGenerationTest extends BaseConfigSuite {
}
}

@Test
def exclusion() = {
check(
"exclusion/pom.xml",
submodules = List(
"exclusion/shims/pom.xml",
"exclusion/api/pom.xml",
"exclusion/consumer/pom.xml"
)
) {
case (_, _, List(_, apiConfig, consumerConfig)) =>
// api depends on shims — shims output dir must be on api's classpath
assert(
hasCompileClasspathEntryName(apiConfig, "shims"),
"api should have shims on its compile classpath"
)

// consumer explicitly excludes shims — its output dir must NOT appear
assert(
!hasCompileClasspathEntryName(consumerConfig, "shims"),
"consumer should not have shims on its compile classpath"
)

// api itself must still be on consumer's classpath
assert(
hasCompileClasspathEntryName(consumerConfig, "api"),
"consumer should still have api on its compile classpath"
)
case _ =>
assert(false, "exclusion should have exactly three submodules")
}
}

@Test
def runtimeDependency() = {
check("runtime_dependency/pom.xml") { (configFile, projectName, subprojects) =>
Expand Down