Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resolution of test-jar artifacts #1747

Merged
merged 3 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import scala.util.Success
import scala.util.Try
import bloop.config.Config
import bloop.config.Tag
import org.apache.maven.RepositoryUtils
import org.apache.maven.artifact.Artifact
import org.apache.maven.artifact.ArtifactUtils
import org.apache.maven.execution.MavenSession
Expand Down Expand Up @@ -84,15 +85,7 @@ object MojoImplementation {
val suffix = if (classifier.nonEmpty) s":$classifier" else ""
log.info("Resolving artifact: " + artifact + suffix)
val request = new ArtifactRequest()
request.setArtifact(
new DefaultArtifact(
artifact.getGroupId(),
artifact.getArtifactId(),
classifier,
artifact.getType(),
artifact.getVersion()
)
)
request.setArtifact(RepositoryUtils.toArtifact(artifact))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading https://github.com/apache/maven/blob/master/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java#L56-L60 I can see it's an internal tool and shouldn't be used, hence I will revert it.

Will need to duplicate some of its logic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 8a606df

request.setRepositories(mojo.getRemoteRepositories())
val result = mojo.getRepoSystem().resolveArtifact(session.getRepositorySession(), request)
log.info("SUCCESS " + artifact)
Expand Down Expand Up @@ -192,9 +185,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) =>
Expand Down
57 changes: 57 additions & 0 deletions integrations/maven-bloop/src/test/resources/test_jars/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<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>test_jars</artifactId>
<version>1.0-SNAPSHOT</version>
<name>test_jars</name>
<description>A minimal Scala project using the Maven build tool.</description>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
<scala.version>2.13.6</scala.version>
</properties>

<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.13.6</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-tags_2.13</artifactId>
<type>test-jar</type>
<scope>test</scope>
<version>3.3.0</version>
</dependency>
</dependencies>

<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.3.2</version>
<configuration></configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args></args>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down