gradle - 如何将 jar 发布到 NEXUS 存储库
问题描述
我想从我的 Gradle 项目中构建一个 jar 并将其推送到 nexus 存储库。作为其中的一部分,我创建了一个 Jenkins 文件并在 build.gradle 中添加了一个任务“发布”任务。
我的詹金斯文件:
pipeline {
agent any
environment {
NEXUS = credentials('nexus-user')
}
options {
ansiColor('xterm')
buildDiscarder logRotator(daysToKeepStr: '30', numToKeepStr: '100')
}
triggers { pollSCM('H/5 * * * *') }
stages {
stage('Checkout'){
steps { checkout scm }
}
stage('Build') {
steps { sh "./gradlew assemble" }
}
stage('deploy') {
steps {
sh "gradle -Duser.home=\"$WORKSPACE\" --gradle-user-home=\"$WORKSPACE/.gradle\" -PnexusUsername=$NEXUS_USR -PnexusPassword=$NEXUS_PSW publish"
}
}
}
}
和 build.gradle
publishing {
publications{
maven(MavenPublication){
artifactId = "testApp"
from components.java
}
}
repositories {
maven {
url = "http://localhost:8081/nexus/content/repositories/${version.endsWith('-SNAPSHOT') ? "snapshots" : "releases"}"
credentials {
username = "Dont know how to pass the username here"
password = "Dont know how to pass the password here"
}
}
}
}
谁能告诉我如何从 Gradle 获取用户名和密码并在此处设置以将 jar 发布到 nexus。
解决方案
答案是:
publishing {
publications{
maven(MavenPublication){
artifactId = "testApp"
from components.java
}
}
repositories {
maven {
url = "http://localhost:8081/nexus/content/repositories/${version.endsWith('-SNAPSHOT') ? "snapshots" : "releases"}"
credentials {
username = "nexusUsername"
password = "nexusPassword"
}
}
}
}
推荐阅读
- postgresql - Travis CI 忽略 Postgres 版本规范
- composer-php - 具有别名的作曲家:无法打开输入文件
- java - 在抽屉外单击时Android导航抽屉不会关闭(主要活动中的片段)
- tensorflow - 使用 word2vec 进行电子邮件分类
- amazon-web-services - awscli列出ownerid创建的所有对象?
- python - 按日期将行透视到列 pandas
- c - 为什么 4 线程程序在 1 核 VM 上比在具有 4 核的同一 VM 上运行得更快?
- java - Elasticsearch嵌套排序 - 文档和用于排序的嵌套对象之间不匹配
- javascript - 使用原型时从类中获取方法
- c# - 阶乘计算器呈现一个负数,应该是正数。怎么修?