简体   繁体   中英

How to include external library for maven on CircleCI

I am using circleCI for a webapp's continuous integration which is built with maven. I want to let maven use an external library when running test and building on CircleCI.
Since the library has just an artifact of a sibling project in a larger parent maven project, I can build this project without any problem on my local environment because I've already add it as a dependency in my pom.xml.
I have tried to add the built jar file into M2_HOME manually with circle.yml and bash file below.

circle.yml:

#...
dependencies:
    pre:
        - sudo chmod a+x add_dependencies.sh
        - ./add_dependencies.sh
#...

add_dependencies.sh:

sudo wget http://my.jar.file.url -O exteral_lib.jar --quiet
sudo mkdir -p ${HOME}/.m2/repository/com/group/artifact/1.0.0/
sudo cp -rl ./exteral_lib.jar ${HOME}/.m2/repository/com/group/artifact/1.0.0/exteral_lib.jar
sudo rm -f ./exteral_lib.jar

But it didn't work.

Failed to create parent directories for tracking file, 
Non-resolvable import POM: Could not transfer artifact 

happened when CircleCI trying to resolve dependencies.

How can I solve this problem?

Instead of copying the jar to the repository, you could try to install it:

mvn install:install-file -DgroupId=<your group id> -DartifactId=<your artifact id> -Dversion=<your version id> -Dpackaging=jar -Dfile=<your jar filename> -DgeneratePom=true

Example:

mvn install:install-file -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc -Dversion=4.2 -Dpackaging=jar -Dfile=sqljdbc.jar -DgeneratePom=true

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