@@ -4,7 +4,7 @@ import groovy.lang.GroovyClassLoader
44import mill .api .Result
55import mill .api .TaskCtx
66import mill .javalib .api .CompilationResult
7- import mill .groovylib .worker .api .GroovyWorker
7+ import mill .groovylib .worker .api .{ GroovyCompilerConfiguration , GroovyWorker }
88import org .codehaus .groovy .control .{CompilationUnit , CompilerConfiguration , Phases }
99import org .codehaus .groovy .tools .javac .JavaStubCompilationUnit
1010import os .Path
@@ -17,22 +17,26 @@ class GroovyWorkerImpl extends GroovyWorker {
1717 override def compileGroovyStubs (
1818 sourceFiles : Seq [Path ],
1919 classpath : Seq [Path ],
20- outputDir : Path
20+ outputDir : Path ,
21+ config : GroovyCompilerConfiguration ,
2122 )(implicit ctx : TaskCtx ): Result [CompilationResult ] = {
22- val config = new CompilerConfiguration ()
23- config .setTargetDirectory(outputDir.toIO)
24- config .setClasspathList(classpath.map(_.toIO.getAbsolutePath).asJava)
25- config .setJointCompilationOptions(Map (
23+ val compilerConfig = new CompilerConfiguration ()
24+ compilerConfig .setTargetDirectory(outputDir.toIO)
25+ compilerConfig .setClasspathList(classpath.map(_.toIO.getAbsolutePath).asJava)
26+ compilerConfig .setJointCompilationOptions(Map (
2627 " stubDir" -> outputDir.toIO,
2728 " keepStubs" -> false
2829 ).asJava)
30+ compilerConfig.setDisabledGlobalASTTransformations(config.disabledGlobalAstTransformations.asJava)
31+ compilerConfig.setPreviewFeatures(config.enablePreview)
32+ config.targetBytecode.foreach(compilerConfig.setTargetBytecode)
2933
3034 // we need to set the classloader for groovy to use the worker classloader
3135 val parentCl : ClassLoader = this .getClass.getClassLoader
32- // config in the GroovyClassLoader is needed when the CL itself is compiling classes
33- val gcl = new GroovyClassLoader (parentCl, config )
34- // config for actual compilation
35- val stubUnit = JavaStubCompilationUnit (config , gcl)
36+ // compilerConfig in the GroovyClassLoader is needed when the CL itself is compiling classes
37+ val gcl = new GroovyClassLoader (parentCl, compilerConfig )
38+ // compilerConfig for actual compilation
39+ val stubUnit = JavaStubCompilationUnit (compilerConfig , gcl)
3640
3741 sourceFiles.foreach { sourceFile =>
3842 stubUnit.addSource(sourceFile.toIO)
@@ -51,26 +55,28 @@ class GroovyWorkerImpl extends GroovyWorker {
5155 def compile (
5256 sourceFiles : Seq [os.Path ],
5357 classpath : Seq [os.Path ],
54- outputDir : os.Path
58+ outputDir : os.Path ,
59+ config : GroovyCompilerConfiguration ,
5560 )(implicit
5661 ctx : TaskCtx
5762 ): Result [CompilationResult ] = {
5863
5964 val extendedClasspath = classpath :+ outputDir
6065
61- val config = new CompilerConfiguration ()
62- config .setTargetDirectory(outputDir.toIO)
63- config .setClasspathList(extendedClasspath.map(_.toIO.getAbsolutePath).asJava)
64- // TODO
65- // config.setDisabledGlobalASTTransformations( )
66- // config.setSourceEncoding( )
66+ val compilerConfig = new CompilerConfiguration ()
67+ compilerConfig .setTargetDirectory(outputDir.toIO)
68+ compilerConfig .setClasspathList(extendedClasspath.map(_.toIO.getAbsolutePath).asJava)
69+ compilerConfig.setDisabledGlobalASTTransformations(config.disabledGlobalAstTransformations.asJava)
70+ compilerConfig.setPreviewFeatures(config.enablePreview )
71+ config.targetBytecode.foreach(compilerConfig.setTargetBytecode )
6772
6873 // we need to set the classloader for groovy to use the worker classloader
6974 val parentCl : ClassLoader = this .getClass.getClassLoader
70- // config in the GroovyClassLoader is needed when the CL itself is compiling classes
71- val gcl = new GroovyClassLoader (parentCl, config)
72- // config for actual compilation
73- val unit = new CompilationUnit (config, null , gcl)
75+ // compilerConfig in the GroovyClassLoader is needed when the CL itself is compiling classes
76+ val gcl = new GroovyClassLoader (parentCl, compilerConfig)
77+
78+ // compilerConfig for actual compilation
79+ val unit = new CompilationUnit (compilerConfig, null , gcl)
7480
7581 sourceFiles.foreach { sourceFile =>
7682 unit.addSource(sourceFile.toIO)
0 commit comments