Groovy + Java 混合编程计划:GMaven
Hava a look
先看成果。在我的项目中轻易创立一个 SayHiUtil.groovy
,而后在 main
外面增加个执行打印一下
package com.cmb.lr20.zxb.dialog.utils
class SayHIUtil {static def sayHi() {println "Hi groovy"}
}
public class DialogApplication {public static void main(String[] args) {SayHIUtil.sayHi();
SpringApplication.run(DialogApplication.class, args);
}
}
DO IT!
应用GMavenPlus
,只需加个 plugin 和 dependency 即可:
<dependencies>
<!-- Groovy -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>3.0.9</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.13.1</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>compileTests</goal>
<goal>removeStubs</goal>
<goal>removeTestStubs</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- if including source jars, use the no-fork goals
otherwise both the Groovy sources and Java stub sources
will get included in your jar -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<!-- source plugin \> = 2.1 is required to use the no-fork goals -->
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
<goal>test-jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>