【问题标题】:How to directly upload a jar file to nexus repository using maven without pom file or settings.xml file?如何使用没有pom文件或settings.xml文件的maven直接将jar文件上传到nexus存储库?
【发布时间】:2019-08-12 19:59:41
【问题描述】:

上下文:我没有对 Nexus 存储库的 UI 访问权限,但我可以访问配置为访问 Nexus 存储库的 Jenkins。我的 git 存储库中有一个带阴影的 jar,需要使用没有 pom.xml 或 settings.xml 文件的 maven 直接上传到 nexus 存储库。

问题:如何使用 Jenkins 和 maven 插件将 git repo 中的 jar 上传到 nexus 存储库?

我尝试搜索此特定用例,但找不到解决方案。

【问题讨论】:

  • 为什么没有 settings.XML?似乎是一个奇怪的约束。如果你没有 pom.XML,好吧,可以使用 deploy 生成一个。

标签: maven nexus


【解决方案1】:

上面的 deploy:deploy-file 解决方案仍然需要一个 settings.xml 文件。登录凭证将使用在 repositoryId 参数中指定的 ID 从 setting.xml “servers”部分检索。我知道没有任何方法可以在没有 settings.xml 文件的情况下使用 Maven 进行部署。但您可以使用“mvn -s some/path/settings.xml”指定自定义 settings.xml 文件。

或者,您可以使用 Jenkins 插件进行部署:https://help.sonatype.com/integrations/nexus-and-continuous-integration/nexus-platform-plugin-for-jenkins#NexusPlatformPluginforJenkins-RepositoryManager3Integration

【讨论】:

    【解决方案2】:

    您可以创建一个 Jenkins Job 来克隆 git 存储库 [Source Code Management],其中存在所需的 jar,并使用以下 maven 命令 [Execute Shell] 配置 Jenkins Job Build 阶段:

    mvn deploy:deploy-file \
        -DgroupId=com.example.test \
        -DartifactId=test-module \
        -Dversion=1.0.0 \
        -DgeneratePom=true \
        -Dpackaging=jar \
        -DrepositoryId=sample-rel \
        -Durl=http://nexus.private.net/Your_Nexus_Repository_Path \
        -Dfile=./PATH_TO_JAR_FILE
    

    (编辑:多行以提高可读性)

    【讨论】:

    • 您的网址参数还需要一个“-”
    猜你喜欢
    • 2021-02-27
    • 2020-04-29
    • 1970-01-01
    • 2017-06-16
    • 2014-09-13
    • 2017-05-19
    • 2016-12-07
    • 2021-12-11
    • 2012-07-15
    相关资源
    最近更新 更多