因此,我浪费了一两天(投资)只是为了了解如何使用Gradle将JAR发布到本地运行的Artifactory服务器。 我使用Gradle Artifactory插件进行发布。 我迷失了无穷循环,包括各种版本的各种插件和执行各种任务。 是的,我之前阅读过文档。 只是错了 也许与此同时,情况有所好转。
执行以下操作仅上载了构建信息。 尚未发布工件(JAR)。
$ gradle artifactoryPublish
:artifactoryPublish
Deploying build info to: http://localhost:8081/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://localhost:8081/artifactory/webapp/builds/scala-gradle-artifactory/1408198981123/2014-08-16T16:23:00.927+0200/BUILD SUCCESSFULTotal time: 4.681 secs
这个人救了我,我想亲他一下: StackOverflow –使用gradle将工件上传到工件
我假设您已经安装了Gradle和Artifactory。 我有一个Scala项目,但这没关系。 Java应该没问题。 我在端口8081上本地运行Artifactory。我还创建了一个名为devuser
的新用户,该用户有权部署工件。
长话短说,这是我最后的build.gradle
脚本文件:
buildscript {repositories {maven {url 'http://localhost:8081/artifactory/plugins-release'credentials {username = "${artifactory_user}"password = "${artifactory_password}"}name = "maven-main-cache"}}dependencies {classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"}
}apply plugin: 'scala'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"version = '1.0.0-SNAPSHOT'
group = 'com.buransky'repositories {add buildscript.repositories.getByName("maven-main-cache")
}dependencies {compile 'org.scala-lang:scala-library:2.11.2'
}tasks.withType(ScalaCompile) {scalaCompileOptions.useAnt = false
}artifactory {contextUrl = "${artifactory_contextUrl}"publish {repository {repoKey = 'libs-snapshot-local'username = "${artifactory_user}"password = "${artifactory_password}"maven = true} defaults {publications ('mavenJava')}}
}publishing {publications {mavenJava(MavenPublication) {from components.java}}
}
我已经将Artifactory上下文URL和凭据存储在~/.gradle/gradle.properties
文件中,如下所示:
artifactory_user=devuser
artifactory_password=devuser
artifactory_contextUrl=http://localhost:8081/artifactory
现在,当我再次运行同一任务时,这就是我想要的。 Maven POM文件和JAR存档都已部署到Artifactory:
$ gradle artifactoryPublish
:generatePomFileForMavenJavaPublication
:compileJava UP-TO-DATE
:compileScala UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:artifactoryPublish
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/com/buransky/scala-gradle-artifactory/1.0.0-SNAPSHOT/scala-gradle-artifactory-1.0.0-SNAPSHOT.pom
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/com/buransky/scala-gradle-artifactory/1.0.0-SNAPSHOT/scala-gradle-artifactory-1.0.0-SNAPSHOT.jar
Deploying build info to: http://localhost:8081/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://localhost:8081/artifactory/webapp/builds/scala-gradle-artifactory/1408199196550/2014-08-16T16:26:36.232+0200/BUILD SUCCESSFULTotal time: 5.807 secs
美满结局:
翻译自: https://www.javacodegeeks.com/2014/08/publish-jar-artifact-using-gradle-to-artifactory.html