3

Groovy スクリプトを呼び出す Maven ビルド ファイルを呼び出す Jenkins ジョブがあります。

ジェンキンスには次のものがあります。

Maven version 3.0
Goals and options: -U -P hudson gplus:execute

Groovy スクリプトはGMavenPlusを使用して呼び出されます。私が持っている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>

これはtestImport.groovyスクリプトを呼び出しています:

println "Hello from testImport"
importedClass = new ImportedClass()
importedClass.hello()

このスクリプトは、1 つのメソッドを持つ別の groovy スクリプトImportedClass.groovyをインクルードしようとします。

class ImportedClass {
def hello() {
    println( "Hello from imported class" )
}

}

testImport スクリプトは正しく呼び出され、すべて動作していますが、importedClass のインポートを使用しようとすると問題が発生するようです。

Jenkins コンソールにこのエラーが表示されます

[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>

次に、groovy コードで使用できます。

import groovyx.net.http.HTTPBuilder
// and create instance of the class
def httpBuilder = new HTTPBuilder("blablabla")
4

1 に答える 1

1

GitHub https://github.com/groovy/GMavenPlus/issues/53でこの問題をフォローしました

使用するために与えられた提案を実装しました:

def myDependentScript = new GroovyClassLoader().parseClass(new File("myScriptDependency.groovy")).newInstance()

単純なインポートを使用するほどきれいではありませんが、それでも機能します

于 2016-04-11T14:47:20.550 に答える