I have a Java library pushed on GitHub, and I want to use it in a pipeline.
我在GitHub上推了一个Java库,我想在管道中使用它。
I tried:
@Library('test') _
@Library('test') _
import com.bla.bla.Bla
@Library('test') import com.bla.bla.Bla
I always get:
我总是得到:
unable to resolve class Bla.
无法解决类Bla。
1 个解决方案
#1
2
Please refer to https://jenkins.io/doc/book/pipeline/shared-libraries/
请参阅https://jenkins.io/doc/book/pipeline/shared-libraries/
As said in the section "Using third-party libraries":
如“使用第三方库”一节所述:
It is possible to use third-party Java libraries, typically found in Maven Central, from trusted library code using the @Grab annotation. Refer to the Grape documentation for details, but simply put:
可以使用@Grab注释从受信任的库代码中使用通常在Maven Central中找到的第三方Java库。有关详细信息,请参阅Grape文档,但只需输入:
@Grab('org.apache.commons:commons-math3:3.4.1')
import org.apache.commons.math3.primes.Primes
void parallelize(int count) {
if (!Primes.isPrime(count)) {
error "${count} was not prime"
}
// …
}
Grape documentation: http://docs.groovy-lang.org/latest/html/documentation/grape.html#_quick_start
葡萄文档:http://docs.groovy-lang.org/latest/html/documentation/grape.html#_quick_start
If you want to use a local library or from github the only thing you have to do is to build the project as a maven project and then use @Grab accordingly.
如果您想使用本地库或github,您唯一需要做的就是将项目构建为maven项目,然后相应地使用@Grab。
#1
2
Please refer to https://jenkins.io/doc/book/pipeline/shared-libraries/
请参阅https://jenkins.io/doc/book/pipeline/shared-libraries/
As said in the section "Using third-party libraries":
如“使用第三方库”一节所述:
It is possible to use third-party Java libraries, typically found in Maven Central, from trusted library code using the @Grab annotation. Refer to the Grape documentation for details, but simply put:
可以使用@Grab注释从受信任的库代码中使用通常在Maven Central中找到的第三方Java库。有关详细信息,请参阅Grape文档,但只需输入:
@Grab('org.apache.commons:commons-math3:3.4.1')
import org.apache.commons.math3.primes.Primes
void parallelize(int count) {
if (!Primes.isPrime(count)) {
error "${count} was not prime"
}
// …
}
Grape documentation: http://docs.groovy-lang.org/latest/html/documentation/grape.html#_quick_start
葡萄文档:http://docs.groovy-lang.org/latest/html/documentation/grape.html#_quick_start
If you want to use a local library or from github the only thing you have to do is to build the project as a maven project and then use @Grab accordingly.
如果您想使用本地库或github,您唯一需要做的就是将项目构建为maven项目,然后相应地使用@Grab。