How to simply download a JAR using Maven?

后端 未结 12 553
轮回少年
轮回少年 2020-12-04 10:14

How do I download JAR during a build in Maven script?

相关标签:
12条回答
  • 2020-12-04 10:56

    You can use:

    mvn dependency:copy -Dartifact=<group>:<artifact-name>:<version> -DoutputDirectory=/tmp/my_custom_dir
    

    (Replace <values> with the ones of your case)

    That's the full documentation of the goal: https://maven.apache.org/plugins/maven-dependency-plugin/copy-mojo.html

    Note: the other "dependecy:get" way of doing this has been deprecated.

    0 讨论(0)
  • 2020-12-04 10:59

    See How to use Maven pom to download jar files only. This worked really nicely for me.

    My use case was that I wanted to download some of the dependency jars to deploy to a QA server, and was doing it manually (outside of the Maven build). I'm not sure exactly what your use case is.

    0 讨论(0)
  • 2020-12-04 10:59

    You can download Jar package to specific directory.

    mvn dependency:get -Dartifact=org.riversun:random-forest-codegen:1.0.0 -Ddest=./
    
    0 讨论(0)
  • 2020-12-04 11:02

    Go to http://mvnrepository.com. Search for the artifact you want to download, choose the version from the list of results and simply download the bundle.

    0 讨论(0)
  • 2020-12-04 11:09

    Or since 3.1, simply as mvn dependency:get -Dartifact=org.springframework:spring-instrument:3.2.3.RELEASE

    0 讨论(0)
  • 2020-12-04 11:12

    It's possible to download a JAR from a Gitlab Maven private repository. The URL is appearing when running some Maven command so it's a bit hacky but it's working for me.

    Like this:

    wget --header "PRIVATE-TOKEN: ${GITLAB_PRIVATE_TOKEN}" "https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/packages/maven/${MAVEN_PACKAGE_NAME}/${MAVEN_VERSION}/${JAR_FILE}"
    

    Where,

    • GITLAB_PRIVATE_TOKEN is a Gitlab Token with right "api" (atm the others are not enough)
      • GITLAB_PROJECT_ID e.g. 1462237
      • MAVEN_PACKAGE_NAME e.g. com/bar/foo
      • MAVEN_VERSION e.g. 0.0.1
      • JAR_FILE e.g. foo-0.0.1.jar
    0 讨论(0)
提交回复
热议问题