Skip to content

Commit 2b7064d

Browse files
authored
Fix resolution of test-jar artifacts (scalacenter#1747)
Resolve test-jar dependencies
1 parent 6197f55 commit 2b7064d

File tree

3 files changed

+98
-3
lines changed

3 files changed

+98
-3
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.apache.maven.plugin.logging.Log
2121
import org.apache.maven.project.MavenProject
2222
import org.codehaus.plexus.util.xml.Xpp3Dom
2323
import org.eclipse.aether.artifact.DefaultArtifact
24+
import org.eclipse.aether.artifact.DefaultArtifactType
2425
import org.eclipse.aether.resolution.ArtifactRequest
2526
import scala_maven.AppLauncher
2627

@@ -84,13 +85,24 @@ object MojoImplementation {
8485
val suffix = if (classifier.nonEmpty) s":$classifier" else ""
8586
log.info("Resolving artifact: " + artifact + suffix)
8687
val request = new ArtifactRequest()
88+
val handler = artifact.getArtifactHandler()
89+
val artifactType = new DefaultArtifactType(
90+
artifact.getType(),
91+
handler.getExtension(),
92+
handler.getClassifier(),
93+
handler.getLanguage(),
94+
handler.isAddedToClasspath(),
95+
handler.isIncludesDependencies()
96+
)
8797
request.setArtifact(
8898
new DefaultArtifact(
8999
artifact.getGroupId(),
90100
artifact.getArtifactId(),
91101
classifier,
92-
artifact.getType(),
93-
artifact.getVersion()
102+
handler.getExtension(),
103+
artifact.getVersion(),
104+
null,
105+
artifactType
94106
)
95107
)
96108
request.setRepositories(mojo.getRemoteRepositories())
@@ -192,9 +204,10 @@ object MojoImplementation {
192204
case a: Artifact => a.getArtifactId() == "scala-library"
193205
}
194206
val allArtifacts = if (hasScalaLibrary) artifacts else artifacts ++ libraryAndDependencies
207+
val isJar = Set("jar", "test-jar")
195208
val modules =
196209
allArtifacts.collect {
197-
case art: Artifact if art.getType() == "jar" && isNotReactorProjectArtifact(art) =>
210+
case art: Artifact if isJar(art.getType()) && isNotReactorProjectArtifact(art) =>
198211
if (art.getArtifactId() == "scala-library")
199212
scalaContext match {
200213
case Some(context) =>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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>test_jars</artifactId>
5+
<version>1.0-SNAPSHOT</version>
6+
<name>test_jars</name>
7+
<description>A minimal Scala project using the Maven build tool.</description>
8+
9+
<properties>
10+
<maven.compiler.source>1.8</maven.compiler.source>
11+
<maven.compiler.target>1.8</maven.compiler.target>
12+
<encoding>UTF-8</encoding>
13+
<scala.version>2.13.6</scala.version>
14+
</properties>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.scala-lang</groupId>
19+
<artifactId>scala-library</artifactId>
20+
<version>2.13.6</version>
21+
</dependency>
22+
23+
<!-- Test -->
24+
<dependency>
25+
<groupId>org.apache.spark</groupId>
26+
<artifactId>spark-tags_2.13</artifactId>
27+
<type>test-jar</type>
28+
<scope>test</scope>
29+
<version>3.3.0</version>
30+
</dependency>
31+
</dependencies>
32+
33+
<build>
34+
<sourceDirectory>src/main/scala</sourceDirectory>
35+
<testSourceDirectory>src/test/scala</testSourceDirectory>
36+
<plugins>
37+
<plugin>
38+
<!-- see http://davidb.github.com/scala-maven-plugin -->
39+
<groupId>net.alchim31.maven</groupId>
40+
<artifactId>scala-maven-plugin</artifactId>
41+
<version>3.3.2</version>
42+
<configuration></configuration>
43+
<executions>
44+
<execution>
45+
<goals>
46+
<goal>compile</goal>
47+
<goal>testCompile</goal>
48+
</goals>
49+
<configuration>
50+
<args></args>
51+
</configuration>
52+
</execution>
53+
</executions>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
</project>

integrations/maven-bloop/src/test/scala/bloop/integrations/maven/MavenConfigGenerationSuite.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,31 @@ class MavenConfigGenerationSuite extends BaseConfigSuite {
173173
}
174174
}
175175

176+
@Test
177+
def dependencyTestJars() = {
178+
check("test_jars/pom.xml") { (configFile, projectName, subprojects) =>
179+
assert(subprojects.isEmpty)
180+
assert(configFile.project.`scala`.isDefined)
181+
assertEquals("2.13.6", configFile.project.`scala`.get.version)
182+
assertEquals("org.scala-lang", configFile.project.`scala`.get.organization)
183+
assert(
184+
!configFile.project.`scala`.get.jars.exists(_.toString.contains("scala3-compiler_3")),
185+
"No Scala 3 jar should be present."
186+
)
187+
assert(!hasCompileClasspathEntryName(configFile, "scala3-library_3"))
188+
assert(hasCompileClasspathEntryName(configFile, "scala-library"))
189+
190+
assert(hasTag(configFile, Tag.Library))
191+
val testJar = configFile.project.resolution.get.modules.find(_.name == "spark-tags_2.13")
192+
assert(testJar.exists { m =>
193+
m.artifacts.exists(_.path.toString().endsWith("spark-tags_2.13-3.3.0-tests.jar"))
194+
})
195+
196+
assertNoConfigsHaveAnyJars(List(configFile), List(s"$projectName", s"$projectName-test"))
197+
assertAllConfigsMatchJarNames(List(configFile), List("scala-library", "spark-tags"))
198+
}
199+
}
200+
176201
@Test
177202
def multiModuleTestJar() = {
178203
check(

0 commit comments

Comments
 (0)