所需的所有步骤如下。
1.从版本中删除'-SNAP'后缀并提交到git repo
1.在此提交上创建新的git标签
- Artifactory在Jfrog上使用发布版本而不是-SNAP版本部署
1.在build.gradle中增加版本(如pom.xml),并添加“-SNAP”后缀。
我使用了最受欢迎的Gradle发布插件(https://github.com/researchgate/gradle-release),但无法在Jfrog上使用发布版本部署artifactory(它总是使用SNAP版本)。
下面是我的示例代码…
gradle.build 文件
publishing {
publications {
mavenJava(MavenPublication) {
groupId 'in.org'
artifactId 'some-service'
version "${version}"
from components.java
}
}
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = version.endsWith('SNAP') ? "${snapshot_repository}" : "${release_repository}"
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
defaults {
publications("mavenJava")
publishArtifacts = true
publishPom = true
}
}
resolve {
repository {
repoKey = "${release_repository}"
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
release {
versionPropertyFile = 'gradle.properties'
failOnCommitNeeded = false
failOnPublishNeeded = false
git {
requireBranch.set('release')
}
}
artifactoryDeploy.shouldRunAfter preTagCommit, checkCommitNeeded
updateVersion.doLast {
def buildGradle = file('gradle.properties')
buildGradle.text = buildGradle.text.replaceFirst(~/version = (\d++\.\d++\.\d++)/, 'version = \'$1\'')
}
gradle.properties 文件
artifactory_user=*****
artifactory_password=*****
artifactory_contextUrl=https://jfrog.in/artifactory
version=1.0.1-SNAPSHOT
snapshot_repository=gradle-dev-local
release_repository=gradle-release-local
1条答案
按热度按时间sz81bmfz1#
我们需要使项目模块版本根据环境动态变化。如果env是prod,我们应该从版本中删除-SNAP,如下所述。