Skip to content

Commit 7adc094

Browse files
authored
Merge pull request #142 from dwijrajhari/dwij/fix-exclusion
Fix: Remove excluded modules from classpath
2 parents bc8ab5e + 87b7691 commit 7adc094

6 files changed

Lines changed: 106 additions & 3 deletions

File tree

src/main/scala/bloop/integrations/maven/MojoImplementation.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,18 @@ object MojoImplementation {
291291
val resolution = Some(Config.Resolution(modules))
292292

293293
val (classpath, runtimeClasspath) = {
294+
// keys of artifacts that survived Maven's exclusion resolution for this module.
295+
val resolvedArtifactKeys: Set[String] = project.getArtifacts.asScala
296+
.map(a => ArtifactUtils.versionlessKey(a))
297+
.toSet
298+
294299
val projectDependencies = dependencies.flatMap { d =>
295-
val build = d.getBuild()
296-
if (configuration == "compile") build.getOutputDirectory() :: Nil
297-
else build.getTestOutputDirectory() :: build.getOutputDirectory() :: Nil
300+
if (!resolvedArtifactKeys.contains(ArtifactUtils.versionlessKey(d.getArtifact))) Nil
301+
else {
302+
val build = d.getBuild()
303+
if (configuration == "compile") build.getOutputDirectory() :: Nil
304+
else build.getTestOutputDirectory() :: build.getOutputDirectory() :: Nil
305+
}
298306
}
299307

300308
val cp = classpath0().asScala.toList.asInstanceOf[List[String]].map(u => abs(new File(u)))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>com.example</groupId>
5+
<artifactId>exclusion</artifactId>
6+
<version>0.1</version>
7+
</parent>
8+
<artifactId>api</artifactId>
9+
10+
<dependencies>
11+
<dependency>
12+
<groupId>com.example</groupId>
13+
<artifactId>shims</artifactId>
14+
<version>0.1</version>
15+
</dependency>
16+
</dependencies>
17+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>com.example</groupId>
5+
<artifactId>exclusion</artifactId>
6+
<version>0.1</version>
7+
</parent>
8+
<artifactId>consumer</artifactId>
9+
10+
<dependencies>
11+
<dependency>
12+
<groupId>com.example</groupId>
13+
<artifactId>api</artifactId>
14+
<version>0.1</version>
15+
<exclusions>
16+
<exclusion>
17+
<groupId>com.example</groupId>
18+
<artifactId>shims</artifactId>
19+
</exclusion>
20+
</exclusions>
21+
</dependency>
22+
</dependencies>
23+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.example</groupId>
4+
<artifactId>exclusion</artifactId>
5+
<version>0.1</version>
6+
<packaging>pom</packaging>
7+
8+
<modules>
9+
<module>shims</module>
10+
<module>api</module>
11+
<module>consumer</module>
12+
</modules>
13+
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>com.example</groupId>
5+
<artifactId>exclusion</artifactId>
6+
<version>0.1</version>
7+
</parent>
8+
<artifactId>shims</artifactId>
9+
</project>

src/test/scala/bloop/integrations/maven/MavenConfigGenerationTest.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,39 @@ class MavenConfigGenerationTest extends BaseConfigSuite {
544544
}
545545
}
546546

547+
@Test
548+
def exclusion() = {
549+
check(
550+
"exclusion/pom.xml",
551+
submodules = List(
552+
"exclusion/shims/pom.xml",
553+
"exclusion/api/pom.xml",
554+
"exclusion/consumer/pom.xml"
555+
)
556+
) {
557+
case (_, _, List(_, apiConfig, consumerConfig)) =>
558+
// api depends on shims — shims output dir must be on api's classpath
559+
assert(
560+
hasCompileClasspathEntryName(apiConfig, "shims"),
561+
"api should have shims on its compile classpath"
562+
)
563+
564+
// consumer explicitly excludes shims — its output dir must NOT appear
565+
assert(
566+
!hasCompileClasspathEntryName(consumerConfig, "shims"),
567+
"consumer should not have shims on its compile classpath"
568+
)
569+
570+
// api itself must still be on consumer's classpath
571+
assert(
572+
hasCompileClasspathEntryName(consumerConfig, "api"),
573+
"consumer should still have api on its compile classpath"
574+
)
575+
case _ =>
576+
assert(false, "exclusion should have exactly three submodules")
577+
}
578+
}
579+
547580
@Test
548581
def runtimeDependency() = {
549582
check("runtime_dependency/pom.xml") { (configFile, projectName, subprojects) =>

0 commit comments

Comments
 (0)