将编译的Groovy脚本与GMavenPlus插件一起使用



我正在尝试使用GMavenPlus PluginMaven运行一些Groovy脚本,这些脚本已编译并打包为jar

脚本非常简单:

package foo.bar.scripts
import groovy.transform.Field
@Field
private static final String JAVA_VERSION_PROPERTY_NAME = 'java.version'
@Field
private static final String MAVEN_COMPILER_RELEASE_PROPERTY_NAME = 'maven.compiler.release'
def javaVersion = project.properties[JAVA_VERSION_PROPERTY_NAME]?.trim()
if(javaVersion?.isInteger() && javaVersion.toInteger() >= 9) {
project.properties[MAVEN_COMPILER_RELEASE_PROPERTY_NAME] = javaVersion
}

然后我用调用

<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>scripts</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>adjust-compiler-settings</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<scripts>
<script>foo.bar.scripts.AdjustCompilerSettings.main()</script>
</scripts>
</configuration>
</execution>
</executions>
</plugin>

根据文档,默认情况下project变量应该是可用的,如果我以内联方式定义脚本,而不是从jar中提取脚本,这确实是正确的。我有办法穿过这样的物体吗?

基于给定的东西:

<profile>
<id>javac-release</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<properties>
<maven.compiler.release>8</maven.compiler.release>
</properties>
</profile>

我没有找到这个问题的解决方案,但我找到了(某种程度上(解决方法。那就是将Groovy源代码打包为jar,发布它们,然后让Maven下载它们(使用maven-dependency-plugin(,并让gmavenplus-plugin调用这些源代码。

不是最好的解决方案,但它有效:(

相关内容

最新更新