美文网首页
Gradle 项目上传和下载 Maven私服的jar文件

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

作者: 科学 | 来源:发表于2016-03-22 18:42 被阅读0次

    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 publishToMavenLocal

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

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

    wdxxl@ubuntu:~$ gedit ~/.gradle/gradle.properties
    
    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'
                }
            }
        }
    }
    
    Image.png
    wdxxl@ubuntu:~/gradle_demo/publishToArtifactory$ gradle publishToMavenLocal
    wdxxl@ubuntu:~/gradle_demo/publishToArtifactory$ gradle artifactoryPublish
    
    .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
    
    注意查看依赖包的路径 一个是.m2的 一个是.gradle的

    相关文章

      网友评论

          本文标题:Gradle 项目上传和下载 Maven私服的jar文件

          本文链接:https://www.haomeiwen.com/subject/qgrllttx.html