Skip to content

Commit c79a19c

Browse files
lostinicelandlefoulihaoyi
authored
Initial Groovy setup (#5747)
I have been working on Groovy support since I would like to use Mill for projects where tests are written in Spock/Groovy. It is basically a modified version of the Kotlin support. Whats currently working: - Groovy compilation (tested with 4 & 5) - Maven project layout with an additional convenience option to configure Groovy for tests only - JUnit5 test execution - Spock tests - CompileStatic - Configure Bytecode Version and Preview If anyone would like to provide feedback I would appreciate it. Pull request: #5747 Co-authored-by: Tobias Roeser <le.petit.fou@web.de> Co-authored-by: Li Haoyi <haoyi.sg@gmail.com>
1 parent 249fb3a commit c79a19c

File tree

83 files changed

+2225
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+2225
-8
lines changed

.github/workflows/run-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ jobs:
157157
millargs: "example.androidlib.__.shared.daemon"
158158
setup-android: true
159159

160+
- java-version: 17
161+
millargs: "'example.groovylib.__.shared.daemon'"
162+
setup-android: true
163+
160164
- java-version: 17
161165
millargs: "example.thirdparty.android-compose-samples.packaged.daemon"
162166
setup-android: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package mill.api.daemon.internal
2+
3+
@mill.api.daemon.experimental
4+
trait GroovyModuleApi extends JavaModuleApi

core/api/daemon/src/mill/api/daemon/internal/bsp/BspModuleApi.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ object BspModuleApi {
2323
val Java = "java"
2424
val Scala = "scala"
2525
val Kotlin = "kotlin"
26+
val Groovy = "groovy"
2627
}
2728

2829
/** Used to define the [[BspBuildTarget.tags]] field. */

core/eval/src/mill/eval/ScriptModuleInit.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ScriptModuleInit extends ((String, Evaluator) => Seq[Result[ExternalModule
5353
case "java" => Result.Success("mill.script.JavaModule")
5454
case "kt" => Result.Success("mill.script.KotlinModule")
5555
case "scala" => Result.Success("mill.script.ScalaModule")
56+
case "groovy" => Result.Success("mill.script.GroovyModule")
5657
case _ =>
5758
Result.Failure(
5859
s"Script ${scriptFile.relativeTo(mill.api.BuildCtx.workspaceRoot)} has no `extends` clause configured and is of an unknown extension `${scriptFile.ext}`"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Foo {
2+
3+
static void main(String[] args) {
4+
if(args == null || args.length != 1){
5+
println "Specify exactly one parameter for greeting"
6+
System.exit(1)
7+
}
8+
9+
println "Hello ${args[0]}"
10+
}
11+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// SNIPPET:FILE
2+
/** See Also: Foo.groovy */
3+
//// SNIPPET:END
4+
5+
//// SNIPPET:CMD
6+
/** Usage
7+
> ./mill Foo.groovy bar
8+
Compiling 1 Groovy sources to...
9+
Hello bar
10+
*/
11+
//// SNIPPET:END
12+
//// SNIPPET:MORE
13+
14+
/** Usage
15+
> ./mill Foo.groovy:run bar
16+
Hello bar
17+
*/
18+
19+
//// SNIPPET:END
20+
21+
//// SNIPPET:RESOLVE
22+
/** Usage
23+
24+
> ./mill resolve Foo.groovy:_
25+
Foo.groovy:run
26+
Foo.groovy:runMain
27+
Foo.groovy:compile
28+
Foo.groovy:assembly
29+
...
30+
31+
*/
32+
//// SNIPPET:END
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This is a basic Mill build for a single `GroovyModule`, with one
2+
// third-party dependency and a test suite using the JUnit framework.
3+
//
4+
// This example project uses two third-party dependencies
5+
// - Groovy-Cli-Commons for CLI argument parsing
6+
// - Groovy-Xml for HTML templating and escaping
7+
// and uses them to wrap a given input string in HTML templates with proper escaping.
8+
//
9+
10+
/** See Also: build.mill.yaml */
11+
/** See Also: test/package.mill.yaml */
12+
13+
/** Usage
14+
15+
> ./mill resolve _ # List what tasks are available to run
16+
assembly
17+
...
18+
compile
19+
...
20+
run
21+
...
22+
test
23+
24+
*/
25+
26+
/** Usage
27+
> ./mill run --text hello
28+
<h1>hello</h1>
29+
*/
30+
31+
/** Usage
32+
> ./mill test
33+
Running Test Class foo.FooTest
34+
Test foo.FooTest#generate html created properly() finished...
35+
Test foo.FooTest#generated html is properly escaped() finished...
36+
Test foo.FooTest finished...
37+
38+
*/
39+
40+
/** Usage
41+
> ./mill assembly # bundle classfiles and libraries into a jar for deployment
42+
43+
> ./mill show assembly # show the output of the assembly task
44+
".../out/assembly.dest/out.jar"
45+
46+
> java -jar ./out/assembly.dest/out.jar --text hello
47+
<h1>hello</h1>
48+
49+
*/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extends: [mill.groovylib.GroovyModule]
2+
groovyVersion: 5.0.3
3+
mvnDeps:
4+
- org.apache.groovy:groovy-cli-commons
5+
- org.apache.groovy:groovy-xml
6+
mainClass: foo.Foo
7+
groovyCompileTargetBytecode: '11'
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package foo
2+
3+
import groovy.xml.MarkupBuilder
4+
import groovy.cli.commons.CliBuilder
5+
6+
class Foo {
7+
static String generateHtml(String text) {
8+
def writer = new StringWriter()
9+
new MarkupBuilder(writer).h1 {
10+
mkp.yield text
11+
}
12+
writer.toString()
13+
}
14+
15+
static void main(String[] args) {
16+
def cli = new CliBuilder(usage:'help')
17+
cli.t(longOpt:'text', args: 1, 'Passes text to the HTML generation')
18+
def options = cli.parse(args)
19+
20+
if (!options) {
21+
return
22+
}
23+
24+
if (options.h) {
25+
cli.usage()
26+
return
27+
}
28+
29+
String textToProcess = options.t ?: "hello from main"
30+
println generateHtml(textToProcess)
31+
}
32+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extends: [build.GroovyTests, mill.javalib.TestModule.Junit5]
2+
jupiterVersion: 5.13.4
3+
mvnDeps:
4+
- org.apache.groovy:groovy-test

0 commit comments

Comments
 (0)