简体   繁体   中英

How do I import a Java library in Jenkins pipeline

I have a Java library pushed on GitHub, and I want to use it in a pipeline.

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.

Please refer to 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('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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM