2014-12-31 41 views
0

我有我有搖籃建設多項目構建:固定搖籃Artifactory的插件出版發行

myapp/ 
    myapp-client/ 
    myapp-shared/ 
    myapp-server/ 
    build.gradle 
    settings.gradle 

settings.gradle樣子:

include ':myapp-shared' 
include ':myapp-client' 
include ':myapp-server' 

我已經成功地得到了搖籃編譯我Groovy源代碼,運行單元測試,生成GroovyDocs,併爲所有3個子項目打包二進制和源JAR。構建調用爲:gradle clean build groovydoc sourcesJar -Pversion=<whatever version I specify>

我現在嘗試添加的搖籃,Artifactory的插件使得:

  • 所有3個子項目獲得他們所產生的POM;和
  • 所有3個子項目二進制JAR,POM 源JAR發佈到我的本地運行的Artifactory;和
  • artifactoryPublish任務執行時gradle build調用

這是我最好的嘗試(我的完整build.gradle):

allprojects { 
    buildscript { 
     repositories { 
      maven { 
       url 'http://localhost:8081/artifactory/plugins-release' 
       credentials { 
        username = "admin" 
        password = "password" 
       } 
       name = "maven-main-cache" 
      } 
     } 
     dependencies { 
      classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1" 
     } 
    } 

    apply plugin: 'groovy' 
    apply plugin: 'maven' 
    apply plugin: 'maven-publish' 
    apply plugin: "com.jfrog.artifactory" 

    version="0.0.1" 
    group = "mygroup" 

    repositories { 
     mavenCentral() 
     add buildscript.repositories.getByName("maven-main-cache") 
     maven { 
      url "http://localhost:8081/artifactory/mydev-snapshots" 
     } 
    } 

    artifactory { 
     contextUrl = "http://localhost:8081/artifactory" 
     publish { 
      repository { 
       repoKey = 'mydev-snapshots' 
       username = "admin" 
       password = "password" 
       maven = true 
      } 
      defaults { 
       publications ('mavenJava') 
      } 
     } 
    } 

    publishing { 
     publications { 
      mavenJava(MavenPublication) { 
       from components.java 
      } 
     } 
    } 
} 

rootProject { 
    artifactoryPublish.skip=true 
} 

subprojects { 
    apply plugin: 'groovy' 
    apply plugin: 'eclipse' 

    sourceCompatibility = '1.7' 
    targetCompatibility = '1.7' 

    [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' 

    repositories { 
     mavenLocal() 
     mavenCentral() 
     maven { 
      url "https://repository.apache.org/content/repositories/snapshots" 
     } 
     maven { 
      url "http://localhost:8081/artifactory/mydev-snapshots" 
     } 
     maven { 
      url "https://code.google.com/p/guava-libraries/" 
     } 
    } 

    dependencies { 
     compile (
      'org.codehaus.groovy:groovy-all:2.3.7' 
     ) 
    } 

    task sourcesJar(type: Jar, dependsOn: classes) { 
     classifier = 'sources' 
     from sourceSets.main.allSource 
    } 

    task wrapper(type: Wrapper) { 
     gradleVersion = '1.11' 
    } 

    build(dependsOn: 'artifactoryPublish') 
} 

當我運行gradle clean build groovydoc sourcesJar -Pversion=0.1.1,我得到了下面的命令行例外:

FAILURE: Build failed with an exception. 

* Where: 
Build file 'C:\Users\myuser\sandbox\eclipse\workspace\myapp\build.gradle' line: 14 

* What went wrong: 
A problem occurred evaluating root project 'myapp'. 
> You can't change a configuration which is not in unresolved state! 

* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 

BUILD FAILED 

Total time: 2.589 secs 

我的問題:發生了什麼事在這裏,我需要做什麼(特別是)來修復它並獲得Artifactory插件發佈?

獎金的問題:。我在兩個地方指定版本號(編譯調用還有build.gradle文件裏面我想通過構建調用指定版本號只有如何配置artifactoryPublish(或者說,搖籃,Artifactory的插件)接受我的命令行指定版本

回答

3

問題的數字在這裏:

  1. buildscript應該是頂級塊,正OT內allprojects
  2. 當使用Artifactory的,如果你想使用artifactoryPublish您需要配置Artifactory的插件,你不需要除了Artifactory的(不需要mavenCentral()
  3. 的指定任何其他存儲庫。 Here are the docs以下是多模塊Gradle項目的兩個完整示例:12。一些亮點:
    1. 您需要申請mavenmaven-publish插件。
    2. 您需要相應地將製作的製品添加到configurationpublication
    3. 您需要爲您正在使用的Artifactory實例配置插件,提供解析和部署存儲庫名稱,憑據(通常僅用於部署)並指定要發佈哪個configurationpublication
+0

鏈接到多模塊Gradle項目示例不工作:-( –