Gradle 项目上传和下载 Maven私服的jar文件

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'
            }
        }
    }
}
Gradle 项目上传和下载 Maven私服的jar文件_第1张图片
gradle publishToMavenLocal

02. 上传编译好的文件到 Artifactory Maven私服

Gradle 创建项目, 并且发布到artifactory中,另外一个项目下载使用
http://buransky.com/scala/publish-jar-artifact-using-gradle-to-artifactory/

wdxxl@ubuntu:~$ gedit ~/.gradle/gradle.properties
Gradle 项目上传和下载 Maven私服的jar文件_第2张图片
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'
            }
        }
    }
}
Gradle 项目上传和下载 Maven私服的jar文件_第3张图片
Image.png
wdxxl@ubuntu:~/gradle_demo/publishToArtifactory$ gradle publishToMavenLocal
wdxxl@ubuntu:~/gradle_demo/publishToArtifactory$ gradle artifactoryPublish
Gradle 项目上传和下载 Maven私服的jar文件_第4张图片
.m2 & artifactory

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
Gradle 项目上传和下载 Maven私服的jar文件_第5张图片
注意查看依赖包的路径 一个是.m2的 一个是.gradle的

你可能感兴趣的:(Gradle 项目上传和下载 Maven私服的jar文件)