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
18 changes: 15 additions & 3 deletions src/main/scala/bloop/integrations/maven/MojoImplementation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ object MojoImplementation {
classesDir0: File,
// needs to be lazy, since we resolve artifacts later on
classpath0: () => java.util.List[_],
runtimeClasspath0: Option[() => java.util.List[_]],
resources0: java.util.List[_],
launcher: Option[AppLauncher],
configuration: String
Expand Down Expand Up @@ -289,7 +290,7 @@ object MojoImplementation {

val resolution = Some(Config.Resolution(modules))

val classpath = {
val (classpath, runtimeClasspath) = {
val projectDependencies = dependencies.flatMap { d =>
val build = d.getBuild()
if (configuration == "compile") build.getOutputDirectory() :: Nil
Expand All @@ -302,7 +303,16 @@ object MojoImplementation {

val fullClasspath =
if (hasScalaLibrary) cp else cp ++ libraryAndDependencies.map(_.getFile().toPath())
(projectDependencies.map(u => abs(new File(u))) ++ fullClasspath ++ extraClasspath).toList
val compileCp =
(projectDependencies.map(u => abs(new File(u))) ++ fullClasspath ++ extraClasspath).toList

val runtimeCp = runtimeClasspath0.flatMap { getRuntimeCp =>
val runtimeElements =
getRuntimeCp().asScala.toList.asInstanceOf[List[String]].map(u => abs(new File(u)))
Some((compileCp ++ runtimeElements).distinct)
}

(compileCp, runtimeCp)
}

val tags = if (configuration == "test") List(Tag.Test) else List(Tag.Library)
Expand All @@ -324,7 +334,7 @@ object MojoImplementation {
val javaHome = Some(abs(mojo.getJavaHome().getParentFile.getParentFile))
val jvmArgs = launcher.map(_.getJvmArgs.toList).getOrElse(List.empty)
val mainClass = launcher.map(_.getMainClass).filter(_.nonEmpty)
val platform = Some(Config.Platform.Jvm(Config.JvmConfig(javaHome, jvmArgs), mainClass, None, None, None))
val platform = Some(Config.Platform.Jvm(Config.JvmConfig(javaHome, jvmArgs), mainClass, None, runtimeClasspath, None))
val resources = Some(resources0.asScala.toList.flatMap {
case a: Resource =>
val dir = Paths.get(a.getDirectory())
Expand Down Expand Up @@ -366,6 +376,7 @@ object MojoImplementation {
mojo.getCompileSourceDirectories.asScala.toSeq,
mojo.getCompileOutputDir,
project.getCompileClasspathElements,
Some(() => project.getRuntimeClasspathElements()),
project.getResources,
launcher,
"compile"
Expand All @@ -375,6 +386,7 @@ object MojoImplementation {
mojo.getTestSourceDirectories.asScala.toSeq,
mojo.getTestOutputDir,
project.getTestClasspathElements,
None,
project.getTestResources,
launcher,
"test"
Expand Down
55 changes: 55 additions & 0 deletions src/test/resources/runtime_dependency/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<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>runtime_dependency</artifactId>
<version>1.0-SNAPSHOT</version>
<name>runtime_dependency</name>
<description>A Scala project with a runtime-scoped dependency to verify it appears in the bloop runtime classpath.</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>${scala.version}</version>
</dependency>

<!-- Runtime-only dependency: should appear in bloop platform classpath but not compile classpath -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.16</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<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 @@ -543,4 +543,36 @@ class MavenConfigGenerationTest extends BaseConfigSuite {
assertEquals("3.4.2", configFile.project.`scala`.get.version)
}
}

@Test
def runtimeDependency() = {
check("runtime_dependency/pom.xml") { (configFile, projectName, subprojects) =>
assert(subprojects.isEmpty)
assert(configFile.project.`scala`.isDefined)

// logback-classic is runtime-scoped: it must NOT appear on the compile classpath
assert(
!hasCompileClasspathEntryName(configFile, "logback-classic"),
"logback-classic should NOT be on the compile classpath"
)

// but it MUST appear in the JVM platform runtime classpath
assert(
hasRuntimeClasspathEntryName(configFile, "logback-classic"),
"logback-classic should be on the JVM platform runtime classpath"
)

// transitive runtime dep (logback-core) should also be on runtime classpath
assert(
hasRuntimeClasspathEntryName(configFile, "logback-core"),
"logback-core (transitive of logback-classic) should be on the JVM platform runtime classpath"
)

// compile deps must still be present on the runtime classpath
assert(
hasRuntimeClasspathEntryName(configFile, "scala-library"),
"scala-library should still be on the JVM platform runtime classpath"
)
}
}
}