【发布时间】:2014-04-16 15:27:10
【问题描述】:
我是 Gradle 和 Artifactory 的新手,我想将 JAR 文件上传到 Artifactory。
这是我的build.gradle 文件:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'artifactory-publish'
groupId = 'myGroup'
version = '1.0'
def artifactId = projectDir.name
def versionNumber = version
artifactory {
contextUrl = 'http://path.to.artifactory' // base artifactory url
publish {
repository {
repoKey = 'libs-releases' // Artifactory repository key to publish to
username = 'publisher' // publisher user name
password = '********' // publisher password
maven = true
}
}
}
artifactoryPublish {
dependsOn jar
}
运行artifactoryPublish任务后,构建成功如下图:
> gradle artifactoryPublish --stacktrace
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar
:artifactoryPublish
Deploying build info to: http://path.to.artifactory/api/build
BUILD SUCCESSFUL
Total time: 7.387 secs
但是,除了构建信息之外,没有任何内容发送到 Artifactory。
任何帮助将不胜感激。
编辑:
正如 JBaruch 所说,我添加了以下内容:
apply plugin: 'maven-publish'
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
默认部分为人工任务:
defaults {
publications ('mavenJava')
}
现在可以了。
谢谢。
【问题讨论】:
-
感谢您提出非常有用的问题和更新。一条对我有帮助的注释:
defaults实际上在artifactory.publish内部,而不仅仅是在根artifactory任务中。 -
我在博客中总结了这一点:buransky.com/scala/…
-
当我尝试它时,我得到:
Error:(x, 0) Could not find property 'java' on SoftwareComponentInternal set.你能发布完整的脚本吗? -
我正在编写上面的代码来上传我放在我的 gradle 文件夹 (gradle/sample.jar) 中的 jar,我执行并看到只有构建信息被上传。我有2个疑问。首先,我们在哪里指定要上传哪个 jar,我们还没有在任何地方指定路径。其次,如果我在 artifaction.publish 中编写默认部分,我会收到错误 Error:(82, 0) Extension of type 'PublishingExtension' does not exist。当前注册的扩展类型:[DefaultExtraPropertiesExtension, DefaultArtifactPublicationSet_Decorated..任何解决方案??
-
只要我们有
apply plugin: 'maven',就会生成pom文件,如果我们有'apply plugin: 'maven-publish',就会发布jar文件。而且我不必拥有publishing.publications.mavenJava(MavenPublication) { from components.java }。但是你必须有default {publications ('mavenJava'); publishConfigs('archives', 'published') }
标签: gradle build.gradle artifactory publish maven-publish