Jenkins GMavenPlus插件无法在groovy脚本中导入本地类
我有一个Jenkins的工作,它调用一个maven构建文件,该文件调用groovy脚本 在詹金斯,我有:Jenkins GMavenPlus插件无法在groovy脚本中导入本地类,jenkins,groovy,gmaven-plugin,Jenkins,Groovy,Gmaven Plugin,我有一个Jenkins的工作,它调用一个maven构建文件,该文件调用groovy脚本 在詹金斯,我有: Maven version 3.0 Goals and options: -U -P hudson gplus:execute Groovy脚本是使用。在pom.xml中,我有 <plugin> <groupId>org.codehaus.gmavenplus</groupId> <artifactId>gmavenplus-
Maven version 3.0
Goals and options: -U -P hudson gplus:execute
Groovy脚本是使用。在pom.xml中,我有
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
<configuration>
<scripts>
<script>
file:///${project.basedir}/src/main/java/com/mycompany/testImport.groovy
</script>
</scripts>
</configuration>
</plugin>
此脚本尝试包含另一个groovy脚本,ImportedClass.groovy,它有一个方法:
class ImportedClass {
def hello() {
println( "Hello from imported class" )
}
}
testImport脚本的调用是正确的,我已经完成了所有工作,但是在尝试为importedClass使用导入时似乎出现了问题
詹金斯控制台中出现了这个错误
[ERROR] Failed to execute goal org.codehaus.gmavenplus:gmavenplus-plugin:1.5:execute (default-cli) on project com.mycompany: Error occurred while calling a method on a Groovy class from classpath. InvocationTargetException: startup failed:
[ERROR] Script1.groovy: 3: unable to resolve class ImportedClass
[ERROR] @ line 3, column 21.
[ERROR] def importedClass = new ImportedClass()
[ERROR] ^
[ERROR]
[ERROR] 1 error
[ERROR] -> [Help 1]
我试图设置包名并使用评估,但最终总是出现错误。有没有办法包含外部groovy文件
通过在pom.xml中使用以下内容,我成功地实现了外部依赖:
<dependencies>
<dependency>
<groupId>org.codehaus.groovy.modules.http-builder</groupId>
<artifactId>http-builder</artifactId>
<version>0.7</version>
</dependency>
在GitHub中关注此问题 并实施了以下建议:
def myDependentScript = new GroovyClassLoader().parseClass(new File("myScriptDependency.groovy")).newInstance()
它不像使用简单的导入那样干净,但是仍然可以工作
import groovyx.net.http.HTTPBuilder
// and create instance of the class
def httpBuilder = new HTTPBuilder("blablabla")
def myDependentScript = new GroovyClassLoader().parseClass(new File("myScriptDependency.groovy")).newInstance()