mirror of https://github.com/sbt/sbt.git
fix: Java-only tests
**Problem** managedScalaInstance := false fails Java-only tests because the test runner is based on a Scala Runner and sbt 2.x currently derives the ScalaInstance only from update. **Solution** For the purpose of Java-only testing, create a dummy Scala Instance.
This commit is contained in:
parent
15773d0bd7
commit
21a9996b09
|
|
@ -19,14 +19,32 @@ object Compiler:
|
|||
val sh = Keys.scalaHome.value
|
||||
val app = Keys.appConfiguration.value
|
||||
val sv = Keys.scalaVersion.value
|
||||
val managed = Keys.managedScalaInstance.value
|
||||
sh match
|
||||
case Some(h) => scalaInstanceFromHome(h)
|
||||
case _ =>
|
||||
val scalaProvider = app.provider.scalaProvider
|
||||
scalaInstanceFromUpdate
|
||||
if !managed then emptyScalaInstance
|
||||
else scalaInstanceFromUpdate
|
||||
}
|
||||
|
||||
// use the same class loader as the Scala classes used by sbt
|
||||
/**
|
||||
* A dummy ScalaInstance for Java-only projects.
|
||||
*/
|
||||
def emptyScalaInstance: Def.Initialize[Task[ScalaInstance]] = Def.task {
|
||||
makeScalaInstance(
|
||||
"0.0.0",
|
||||
Array.empty,
|
||||
Seq.empty,
|
||||
Seq.empty,
|
||||
Keys.state.value,
|
||||
Keys.scalaInstanceTopLoader.value,
|
||||
)
|
||||
}
|
||||
|
||||
// Use the same class loader as the Scala classes used by sbt
|
||||
// This will fail for "doc" task https://github.com/sbt/sbt/issues/7725
|
||||
// because Scala 3 uses ScalaDocTool configuration to manage doc tools.
|
||||
def optimizedScalaInstance(
|
||||
sv: String,
|
||||
scalaProvider: ScalaProvider
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.2" % Test
|
||||
managedScalaInstance := false
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.example;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public final class ATest {
|
||||
@Test
|
||||
public void testSomething() {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
> test
|
||||
> doc
|
||||
|
|
@ -1 +1 @@
|
|||
libraryDependencies += "com.novocode" % "junit-interface" % "0.8" % "test"
|
||||
libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.2" % Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue