01. 上傳編譯好的文件到 MavenLocal 本地
apply plugin: 'maven-publish'
dependencies{
testCompile 'junit:junit:4.12'
compile 'org.apache.commons:commons-lang3:3.3.2'
}
// add sources java code, for easy to view code inside of jar
task sourceJar (type:Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
// $ gradle publishToMavenLocal
publishing {
publications {
mavenJava(MavenPublication) {
groupId 'com.wdxxl'
artifactId 'PublishTask'
version '1.0.8-SNAPSHOT'
from components.java
artifact(sourceJar) {
classifier = 'sources'
}
}
}
}
02. 上傳編譯好的文件到 Artifactory Maven私服
Gradle 創(chuàng)建項目, 并且發(fā)布到artifactory中十电,另外一個項目下載使用
http://buransky.com/scala/publish-jar-artifact-using-gradle-to-artifactory/
wdxxl@ubuntu:~$ gedit ~/.gradle/gradle.properties
buildscript {
repositories {
mavenLocal()
maven {
url 'http://localhost:8081/artifactory/plugins-release'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven {
url "http://repo.spring.io/milestone"
}
mavenCentral()
maven {
url "http://clojars.org/repo"
}
maven {
url "http://conjars.org/repo"
}
maven {
url "http://repo.typesafe.com/typesafe/simple/maven-releases/"
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
}
}
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"
group 'com.wdxxl'
version '1.4.0'
dependencies {
testCompile 'junit:junit:4.12'
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'wdxxl_repo'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
defaults {
publications ('mavenJava')
}
}
}
// add sources java code, for easy to view code inside of jar
task sourceJar (type:Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar (type: Jar, dependsOn: javadoc) { // (1)
classifier = 'javadoc'
from javadoc.destinationDir
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact(sourceJar) {
classifier = 'sources'
}
artifact (javadocJar) {
classifier = 'javadoc'
}
}
}
}
wdxxl@ubuntu:~/gradle_demo/publishToArtifactory$ gradle publishToMavenLocal
wdxxl@ubuntu:~/gradle_demo/publishToArtifactory$ gradle artifactoryPublish
03. 下載 Artifactory Maven私服的 jar文件
repositories{
mavenLocal()
mavenCentral()
maven {
url 'http://localhost:8081/artifactory/wdxxl_repo'
// url 'http://localhost:8081/artifactory/libs-snapshot'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies{
compile 'com.wdxxl:PublishTask:1.+'
compile 'com.wdxxl:publishToArtifactory:1.+'
compile 'org.apache.commons:commons-lang3:3.4'
}
wdxxl@ubuntu:~/gradle_demo/callPublishTask$ gradle cleanEclipse eclipse