diff --git a/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala b/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala index b8817f68fc..8f6404be48 100644 --- a/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala +++ b/integrations/maven-bloop/src/main/scala/bloop/integrations/maven/MojoImplementation.scala @@ -21,6 +21,7 @@ import org.apache.maven.plugin.logging.Log import org.apache.maven.project.MavenProject import org.codehaus.plexus.util.xml.Xpp3Dom import org.eclipse.aether.artifact.DefaultArtifact +import org.eclipse.aether.artifact.DefaultArtifactType import org.eclipse.aether.resolution.ArtifactRequest import scala_maven.AppLauncher @@ -84,13 +85,24 @@ object MojoImplementation { val suffix = if (classifier.nonEmpty) s":$classifier" else "" log.info("Resolving artifact: " + artifact + suffix) val request = new ArtifactRequest() + val handler = artifact.getArtifactHandler() + val artifactType = new DefaultArtifactType( + artifact.getType(), + handler.getExtension(), + handler.getClassifier(), + handler.getLanguage(), + handler.isAddedToClasspath(), + handler.isIncludesDependencies() + ) request.setArtifact( new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), classifier, - artifact.getType(), - artifact.getVersion() + handler.getExtension(), + artifact.getVersion(), + null, + artifactType ) ) request.setRepositories(mojo.getRemoteRepositories()) @@ -192,9 +204,10 @@ object MojoImplementation { case a: Artifact => a.getArtifactId() == "scala-library" } val allArtifacts = if (hasScalaLibrary) artifacts else artifacts ++ libraryAndDependencies + val isJar = Set("jar", "test-jar") val modules = allArtifacts.collect { - case art: Artifact if art.getType() == "jar" && isNotReactorProjectArtifact(art) => + case art: Artifact if isJar(art.getType()) && isNotReactorProjectArtifact(art) => if (art.getArtifactId() == "scala-library") scalaContext match { case Some(context) => diff --git a/integrations/maven-bloop/src/test/resources/test_jars/pom.xml b/integrations/maven-bloop/src/test/resources/test_jars/pom.xml new file mode 100644 index 0000000000..a236a0c0b6 --- /dev/null +++ b/integrations/maven-bloop/src/test/resources/test_jars/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + com.example + test_jars + 1.0-SNAPSHOT + test_jars + A minimal Scala project using the Maven build tool. + + + 1.8 + 1.8 + UTF-8 + 2.13.6 + + + + + org.scala-lang + scala-library + 2.13.6 + + + + + org.apache.spark + spark-tags_2.13 + test-jar + test + 3.3.0 + + + + + src/main/scala + src/test/scala + + + + net.alchim31.maven + scala-maven-plugin + 3.3.2 + + + + + compile + testCompile + + + + + + + + + + diff --git a/integrations/maven-bloop/src/test/scala/bloop/integrations/maven/MavenConfigGenerationSuite.scala b/integrations/maven-bloop/src/test/scala/bloop/integrations/maven/MavenConfigGenerationSuite.scala index 40ad25942d..91ed5731c3 100644 --- a/integrations/maven-bloop/src/test/scala/bloop/integrations/maven/MavenConfigGenerationSuite.scala +++ b/integrations/maven-bloop/src/test/scala/bloop/integrations/maven/MavenConfigGenerationSuite.scala @@ -173,6 +173,31 @@ class MavenConfigGenerationSuite extends BaseConfigSuite { } } + @Test + def dependencyTestJars() = { + check("test_jars/pom.xml") { (configFile, projectName, subprojects) => + assert(subprojects.isEmpty) + assert(configFile.project.`scala`.isDefined) + assertEquals("2.13.6", configFile.project.`scala`.get.version) + assertEquals("org.scala-lang", configFile.project.`scala`.get.organization) + assert( + !configFile.project.`scala`.get.jars.exists(_.toString.contains("scala3-compiler_3")), + "No Scala 3 jar should be present." + ) + assert(!hasCompileClasspathEntryName(configFile, "scala3-library_3")) + assert(hasCompileClasspathEntryName(configFile, "scala-library")) + + assert(hasTag(configFile, Tag.Library)) + val testJar = configFile.project.resolution.get.modules.find(_.name == "spark-tags_2.13") + assert(testJar.exists { m => + m.artifacts.exists(_.path.toString().endsWith("spark-tags_2.13-3.3.0-tests.jar")) + }) + + assertNoConfigsHaveAnyJars(List(configFile), List(s"$projectName", s"$projectName-test")) + assertAllConfigsMatchJarNames(List(configFile), List("scala-library", "spark-tags")) + } + } + @Test def multiModuleTestJar() = { check(