Skip to content

Commit 0d0d83e

Browse files
Tweak BSP JVM run / test environment handling (#5287)
This is a follow-up of some changes added in #5265. This further changes how we handle `buildTarget/jvmRunEnvironment` and `buildTarget/jvmTestEnvironment` requests, by making sure main classes in test modules are taken into account in `buildTarget/jvmRunEnvironment`, and by cleaning-up some test snapshot data of `buildTarget/jvmTestEnvironment`, so that they don't change too often and are more maintainable.
1 parent acade44 commit 0d0d83e

20 files changed

+551
-28
lines changed

core/api/src/mill/api/internal/bsp/BspRunModuleApi.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ trait BspRunModuleApi extends ModuleApi {
88

99
private[mill] def bspRun(args: Seq[String]): TaskApi[Unit]
1010

11-
private[mill] def bspJvmRunTestEnvironment: TaskApi[(
11+
private[mill] def bspJvmRunEnvironment: TaskApi[(
12+
runClasspath: Seq[Path],
13+
forkArgs: Seq[String],
14+
forkWorkingDir: Path,
15+
forEnv: Map[String, String],
16+
mainClass: Option[String],
17+
localMainClasses: Seq[String]
18+
)]
19+
20+
private[mill] def bspJvmTestEnvironment: TaskApi[(
1221
runClasspath: Seq[Path],
1322
forkArgs: Seq[String],
1423
forkWorkingDir: Path,
1524
forkEnv: Map[String, String],
1625
mainClass: Option[String],
17-
localMainClasses: Option[Seq[String]],
1826
testEnvVars: Option[(
1927
mainClass: String,
2028
testRunnerClasspathArg: String,

integration/ide/bsp-server/resources/project/build.mill

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,27 @@ package build
33
import mill._
44

55
// testing a simple Java module
6-
object `hello-java` extends scalalib.JavaModule
6+
object `hello-java` extends scalalib.JavaModule {
7+
object test extends JavaTests {
8+
import scalalib._
9+
def testFramework = "com.novocode.junit.JUnitFramework"
10+
def mvnDeps = Seq(
11+
mvn"com.github.sbt:junit-interface:0.13.2",
12+
mvn"junit:junit:4.13.2"
13+
)
14+
}
15+
}
716

817
// testing a simple Scala module
918
object `hello-scala` extends scalalib.ScalaModule {
1019
def scalaVersion = Option(System.getenv("TEST_SCALA_2_13_VERSION")).getOrElse(???)
20+
object test extends ScalaTests {
21+
import scalalib._
22+
def testFramework = "utest.runner.Framework"
23+
def mvnDeps = Seq(
24+
mvn"com.lihaoyi::utest:0.8.5"
25+
)
26+
}
1127
}
1228

1329
// testing a simple Kotlin module
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package hellojava;
2+
3+
public final class HelloJavaTest {
4+
public static void main(String[] args) {
5+
System.out.println("Hello from HelloJavaTest");
6+
}
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package hello
2+
3+
object Hello {
4+
def main(args: Array[String]): Unit =
5+
println("Hello")
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package hello
2+
3+
object HelloTest {
4+
def main(args: Array[String]): Unit =
5+
println("Hello from tests")
6+
}

integration/ide/bsp-server/resources/snapshots/build-targets-compile-classpaths.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@
3434
"file:///workspace/hello-java/compile-resources"
3535
]
3636
},
37+
{
38+
"target": {
39+
"uri": "file:///workspace/hello-java/test"
40+
},
41+
"classpath": [
42+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/github/sbt/junit-interface/0.13.2/junit-interface-0.13.2.jar",
43+
"file:///coursier-cache/https/repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar",
44+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0.jar",
45+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar",
46+
"file:///workspace/hello-java/compile-resources",
47+
"file:///workspace/out/hello-java/compile.dest/classes",
48+
"file:///workspace/hello-java/test/compile-resources"
49+
]
50+
},
3751
{
3852
"target": {
3953
"uri": "file:///workspace/hello-kotlin"
@@ -53,6 +67,21 @@
5367
"file:///workspace/hello-scala/compile-resources"
5468
]
5569
},
70+
{
71+
"target": {
72+
"uri": "file:///workspace/hello-scala/test"
73+
},
74+
"classpath": [
75+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala-library/<scala-version>/scala-library-<scala-version>.jar",
76+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/utest_2.13/0.8.5/utest_2.13-0.8.5.jar",
77+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0.jar",
78+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/portable-scala/portable-scala-reflect_2.13/1.1.3/portable-scala-reflect_2.13-1.1.3.jar",
79+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/<scala-version>/scala-reflect-<scala-version>.jar",
80+
"file:///workspace/hello-scala/compile-resources",
81+
"file:///workspace/out/hello-scala/compile.dest/classes",
82+
"file:///workspace/hello-scala/test/compile-resources"
83+
]
84+
},
5685
{
5786
"target": {
5887
"uri": "file:///workspace/lib"

integration/ide/bsp-server/resources/snapshots/build-targets-dependency-modules.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@
3636
},
3737
"modules": []
3838
},
39+
{
40+
"target": {
41+
"uri": "file:///workspace/hello-java/test"
42+
},
43+
"modules": [
44+
{
45+
"name": "com.github.sbt:junit-interface",
46+
"version": "0.13.2"
47+
},
48+
{
49+
"name": "junit:junit",
50+
"version": "4.13.2"
51+
},
52+
{
53+
"name": "junit:junit",
54+
"version": "4.13.2"
55+
},
56+
{
57+
"name": "org.scala-sbt:test-interface",
58+
"version": "1.0"
59+
},
60+
{
61+
"name": "org.hamcrest:hamcrest-core",
62+
"version": "1.3"
63+
}
64+
]
65+
},
3966
{
4067
"target": {
4168
"uri": "file:///workspace/hello-kotlin"
@@ -62,6 +89,37 @@
6289
}
6390
]
6491
},
92+
{
93+
"target": {
94+
"uri": "file:///workspace/hello-scala/test"
95+
},
96+
"modules": [
97+
{
98+
"name": "org.scala-lang:scala-library",
99+
"version": "<scala-version>"
100+
},
101+
{
102+
"name": "com.lihaoyi:utest_2.13",
103+
"version": "0.8.5"
104+
},
105+
{
106+
"name": "org.scala-sbt:test-interface",
107+
"version": "1.0"
108+
},
109+
{
110+
"name": "org.portable-scala:portable-scala-reflect_2.13",
111+
"version": "1.1.3"
112+
},
113+
{
114+
"name": "org.scala-lang:scala-reflect",
115+
"version": "<scala-version>"
116+
},
117+
{
118+
"name": "org.scala-lang:scala-library",
119+
"version": "<scala-version>"
120+
}
121+
]
122+
},
65123
{
66124
"target": {
67125
"uri": "file:///workspace/lib"

integration/ide/bsp-server/resources/snapshots/build-targets-dependency-sources.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424
},
2525
"sources": []
2626
},
27+
{
28+
"target": {
29+
"uri": "file:///workspace/hello-java/test"
30+
},
31+
"sources": [
32+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/github/sbt/junit-interface/0.13.2/junit-interface-0.13.2-sources.jar",
33+
"file:///coursier-cache/https/repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2-sources.jar",
34+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0-sources.jar",
35+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar"
36+
]
37+
},
2738
{
2839
"target": {
2940
"uri": "file:///workspace/hello-kotlin"
@@ -41,6 +52,18 @@
4152
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala-library/<scala-version>/scala-library-<scala-version>-sources.jar"
4253
]
4354
},
55+
{
56+
"target": {
57+
"uri": "file:///workspace/hello-scala/test"
58+
},
59+
"sources": [
60+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala-library/<scala-version>/scala-library-<scala-version>-sources.jar",
61+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/utest_2.13/0.8.5/utest_2.13-0.8.5-sources.jar",
62+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0-sources.jar",
63+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/portable-scala/portable-scala-reflect_2.13/1.1.3/portable-scala-reflect_2.13-1.1.3-sources.jar",
64+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/<scala-version>/scala-reflect-<scala-version>-sources.jar"
65+
]
66+
},
4467
{
4568
"target": {
4669
"uri": "file:///workspace/lib"

integration/ide/bsp-server/resources/snapshots/build-targets-javac-options.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@
4040
],
4141
"classDirectory": "file:///workspace/out/hello-java/compile.dest/classes"
4242
},
43+
{
44+
"target": {
45+
"uri": "file:///workspace/hello-java/test"
46+
},
47+
"options": [],
48+
"classpath": [
49+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/github/sbt/junit-interface/0.13.2/junit-interface-0.13.2.jar",
50+
"file:///coursier-cache/https/repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar",
51+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0.jar",
52+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar",
53+
"file:///workspace/hello-java/compile-resources",
54+
"file:///workspace/out/hello-java/compile.dest/classes",
55+
"file:///workspace/hello-java/test/compile-resources"
56+
],
57+
"classDirectory": "file:///workspace/out/hello-java/test/compile.dest/classes"
58+
},
4359
{
4460
"target": {
4561
"uri": "file:///workspace/hello-kotlin"
@@ -63,6 +79,23 @@
6379
],
6480
"classDirectory": "file:///workspace/out/hello-scala/compile.dest/classes"
6581
},
82+
{
83+
"target": {
84+
"uri": "file:///workspace/hello-scala/test"
85+
},
86+
"options": [],
87+
"classpath": [
88+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala-library/<scala-version>/scala-library-<scala-version>.jar",
89+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/utest_2.13/0.8.5/utest_2.13-0.8.5.jar",
90+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0.jar",
91+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/portable-scala/portable-scala-reflect_2.13/1.1.3/portable-scala-reflect_2.13-1.1.3.jar",
92+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/<scala-version>/scala-reflect-<scala-version>.jar",
93+
"file:///workspace/hello-scala/compile-resources",
94+
"file:///workspace/out/hello-scala/compile.dest/classes",
95+
"file:///workspace/hello-scala/test/compile-resources"
96+
],
97+
"classDirectory": "file:///workspace/out/hello-scala/test/compile.dest/classes"
98+
},
6699
{
67100
"target": {
68101
"uri": "file:///workspace/lib"

integration/ide/bsp-server/resources/snapshots/build-targets-jvm-run-environments.json

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,33 @@
2929
}
3030
]
3131
},
32+
{
33+
"target": {
34+
"uri": "file:///workspace/app/test"
35+
},
36+
"classpath": [
37+
"file:///coursier-cache/https/repo1.maven.org/maven2/ch/qos/logback/logback-core/1.5.15/logback-core-1.5.15.jar",
38+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/mysql/mysql-connector-j/9.1.0/mysql-connector-j-9.1.0.jar",
39+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/slf4j/slf4j-api/2.0.16/slf4j-api-2.0.16.jar",
40+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/google/protobuf/protobuf-java/4.26.1/protobuf-java-4.26.1.jar",
41+
"file:///workspace/lib/compile-resources",
42+
"file:///workspace/lib/resources",
43+
"file:///workspace/out/lib/compile.dest/classes",
44+
"file:///workspace/app/compile-resources",
45+
"file:///workspace/app/resources",
46+
"file:///workspace/out/app/compile.dest/classes",
47+
"file:///workspace/app/test/compile-resources",
48+
"file:///workspace/app/test/resources",
49+
"file:///workspace/out/app/test/compile.dest/classes"
50+
],
51+
"jvmOptions": [],
52+
"workingDirectory": "/workspace",
53+
"environmentVariables": {
54+
"MILL_WORKSPACE_ROOT": "/workspace",
55+
"MILL_TEST_RESOURCE_DIR": "/workspace/app/test/resources"
56+
},
57+
"mainClasses": []
58+
},
3259
{
3360
"target": {
3461
"uri": "file:///workspace/hello-java"
@@ -45,6 +72,35 @@
4572
},
4673
"mainClasses": []
4774
},
75+
{
76+
"target": {
77+
"uri": "file:///workspace/hello-java/test"
78+
},
79+
"classpath": [
80+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/github/sbt/junit-interface/0.13.2/junit-interface-0.13.2.jar",
81+
"file:///coursier-cache/https/repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar",
82+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0.jar",
83+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar",
84+
"file:///workspace/hello-java/compile-resources",
85+
"file:///workspace/hello-java/resources",
86+
"file:///workspace/out/hello-java/compile.dest/classes",
87+
"file:///workspace/hello-java/test/compile-resources",
88+
"file:///workspace/hello-java/test/resources",
89+
"file:///workspace/out/hello-java/test/compile.dest/classes"
90+
],
91+
"jvmOptions": [],
92+
"workingDirectory": "/workspace",
93+
"environmentVariables": {
94+
"MILL_WORKSPACE_ROOT": "/workspace",
95+
"MILL_TEST_RESOURCE_DIR": "/workspace/hello-java/test/resources"
96+
},
97+
"mainClasses": [
98+
{
99+
"className": "hellojava.HelloJavaTest",
100+
"arguments": []
101+
}
102+
]
103+
},
48104
{
49105
"target": {
50106
"uri": "file:///workspace/hello-kotlin"
@@ -78,7 +134,42 @@
78134
"environmentVariables": {
79135
"MILL_WORKSPACE_ROOT": "/workspace"
80136
},
81-
"mainClasses": []
137+
"mainClasses": [
138+
{
139+
"className": "hello.Hello",
140+
"arguments": []
141+
}
142+
]
143+
},
144+
{
145+
"target": {
146+
"uri": "file:///workspace/hello-scala/test"
147+
},
148+
"classpath": [
149+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala-library/<scala-version>/scala-library-<scala-version>.jar",
150+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/utest_2.13/0.8.5/utest_2.13-0.8.5.jar",
151+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0.jar",
152+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/portable-scala/portable-scala-reflect_2.13/1.1.3/portable-scala-reflect_2.13-1.1.3.jar",
153+
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/<scala-version>/scala-reflect-<scala-version>.jar",
154+
"file:///workspace/hello-scala/compile-resources",
155+
"file:///workspace/hello-scala/resources",
156+
"file:///workspace/out/hello-scala/compile.dest/classes",
157+
"file:///workspace/hello-scala/test/compile-resources",
158+
"file:///workspace/hello-scala/test/resources",
159+
"file:///workspace/out/hello-scala/test/compile.dest/classes"
160+
],
161+
"jvmOptions": [],
162+
"workingDirectory": "/workspace",
163+
"environmentVariables": {
164+
"MILL_WORKSPACE_ROOT": "/workspace",
165+
"MILL_TEST_RESOURCE_DIR": "/workspace/hello-scala/test/resources"
166+
},
167+
"mainClasses": [
168+
{
169+
"className": "hello.HelloTest",
170+
"arguments": []
171+
}
172+
]
82173
},
83174
{
84175
"target": {

0 commit comments

Comments
 (0)