[英]Publishing subprojects with the Gradle-Artifactory plugin
I have the following multi-project Gradle build: 我有以下多项目Gradle构建:
myapp/
myapp-client/
build.gradle
src/** (omitted for brevity)
myapp-shared/
build.gradle
src/** (omitted for brevity)
myapp-server
build.gradle
src/** (omitted for brevity)
build.gradle
settings.gradle
Where myapp/build.gradle
looks like: myapp/build.gradle
如下:
subprojects {
apply plugin: 'groovy'
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
repositories {
mavenCentral()
maven {
// My local/private Artifactory
url "http://localhost:8081/artifactory/myapp-snapshots"
}
}
dependencies {
compile (
'org.codehaus.groovy:groovy-all:2.3.7'
)
}
}
And where each of the 3 subproject Gradle files are currently very simple: 目前,3个子项目Gradle文件中的每一个都非常简单:
dependencies {
compile (
'org.apache.commons:commons-lang3:3.3.2'
)
}
Here's what I'm trying to achieve: 这是我想要实现的目标:
gradle clean build -Pversion=0.1.5
from the parent myapp
directory, I want all three subprojects to be built with a version of 0.1.5; myapp
目录运行gradle clean build -Pversion=0.1.5
,我希望所有三个子项目都以0.1.5的版本构建; hence myapp-client-0.1.5.jar
, myapp-shared-0.1.5.jar
and myapp-server-0.1.5.jar
. myapp-client-0.1.5.jar
, myapp-shared-0.1.5.jar
和myapp-server-0.1.5.jar
。 Currently my build already does this, however... The most compact code I've been able to find and test/confirm for publishing a Gradle-built JAR to Artifactory is: 我能够找到并测试/确认将Gradle构建的JAR发布到Artifactory的最紧凑的代码是:
buildscript {
repositories {
maven {
url 'http://localhost:8081/artifactory/plugins-release'
credentials {
username = "admin"
password = "12345"
}
name = "maven-main-cache"
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
}
}
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"
repositories {
add buildscript.repositories.getByName("maven-main-cache")
maven {
url "http://localhost:8081/artifactory/myapp-snapshots"
}
}
artifactory {
contextUrl = "http://localhost:8081/artifactory"
publish {
repository {
repoKey = 'myapp-snapshots'
username = "admin"
password = "12345"
maven = true
}
defaults {
publications ('mavenJava')
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
When I use this snippet inside a test build.gradle
project, and run gradle artifactoryPublish
, it correctly publishes my JAR to Artifactory. 当我在测试
build.gradle
项目中使用此代码段并运行gradle artifactoryPublish
,它会正确地将我的JAR发布到Artifactory。
My question: How can I add this snippet to my project such that running gradle clean build
from the parent dir, on success, produces client and shared JARs being published to Artifactory? 我的问题: 我如何将这个片段添加到我的项目中,以便从父目录运行
gradle clean build
,成功时,会生成发布到Artifactory的客户端和共享JAR?
Although not ideal, I would be willing to make the publishing a separate, second step if its not possible to do all this in one fell swoop. 虽然不理想,但如果不可能一下子完成所有这一切,我愿意将出版单独的第二步。 Any ideas?
有任何想法吗?
Using the artifactory
plugin is the right way to do. 使用
artifactory
插件是正确的方法。 You need to apply it to allprojects
and disable the deployment on the top-level project with artifactoryPublish.skip=true
. 您需要将其应用于
allprojects
项目,并使用artifactoryPublish.skip=true
禁用顶级项目上的部署。 You can find a fully working example of a project much similar to yours here . 你可以找到一个项目的全面工作的例子很多类似于你在这里 。
By default build
is not dependent on artifactoryPublish
,so you need to run gradle build artifactoryPublish
to upload the jars. 默认情况下,
build
不依赖于artifactoryPublish
,因此您需要运行gradle build artifactoryPublish
来上载jar。 The reason is you might want to run a lot of builds until you decide to upload something. 原因是您可能希望运行大量构建,直到您决定上传某些内容。 You can establish the dependency by configuring
build
to be depending on artifactoryPublish
: 您可以通过将
build
配置为依赖artifactoryPublish
来建立依赖关系:
build(dependsOn: 'artifactoryPublish')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.