2015-02-06 57 views
1

我很困惑爲什麼Gradle的uploadArchive正在上傳其他配置的工件。我的理解是,當你聲明一個配置時,它會爲你獲得一個上傳任務,當它被調用時它會上傳分配給它配置的工件。爲什麼uploadArchives從其他配置上傳工件?

這不是我看到的行爲:

apply plugin: 'base' 

configurations { 
    foo 
} 

task fooIt(type: Zip) { 
    from 'blah.txt' 
    baseName 'foo' 
} 

task barIt(type: Zip) { 
    from 'blah.txt' 
    baseName 'bar' 
} 

artifacts { 
    foo fooIt 
} 

repositories { 
    flatDir { 
    name 'local' 
    dirs 'repo' 
    } 
} 

uploadArchives { 
    repositories { 
    add project.repositories.local 
    } 
} 

uploadFoo { 
    repositories { 
    add project.repositories.local 
    } 
} 

在這個例子中,沒有分配給archives配置工件,但是當我打電話gradle uploadArchives將上傳foo的假象。

$ gradle -i uploadArchives 
All projects evaluated. 
Selected primary task 'uploadArchives' from project : 
Tasks to be executed: [task ':fooIt', task ':uploadArchives'] 
:fooIt (Thread[Daemon Thread 17,5,main]) started. 
:fooIt 
Skipping task ':fooIt' as it is up-to-date (took 0.008 secs). 
:fooIt UP-TO-DATE 
:fooIt (Thread[Daemon Thread 17,5,main]) completed. Took 0.017 secs. 
:uploadArchives (Thread[Daemon Thread 17,5,main]) started. 
:uploadArchives 
Executing task ':uploadArchives' (up-to-date check took 0.0 secs) due to: 
    Task has not declared any outputs. 
Publishing configuration: configuration ':archives' 
Publishing to Repository 'local' 
Published :gradle:unspecified:foo.zip to file:/private/tmp/gradle/repo/foo-unspecified.zip 
Published :gradle:unspecified:ivy.xml to file:/private/tmp/gradle/repo/ivy-unspecified.xml 
:uploadArchives (Thread[Daemon Thread 17,5,main]) completed. Took 0.017 secs. 

BUILD SUCCESSFUL 

兩個問題出於此:

  1. 爲什麼fooIt得到執行?
  2. 爲什麼uploadArchives上傳foo的作品?

由於

$ gradle --version 
------------------------------------------------------------ 
Gradle 2.1 
------------------------------------------------------------ 

Build time: 2014-09-08 10:40:39 UTC 
Build number: none 
Revision:  e6cf70745ac11fa943e19294d19a2c527a669a53 

Groovy:  2.3.6 
Ant:   Apache Ant(TM) version 1.9.3 compiled on December 23 2013 
JVM:   1.7.0_45 (Oracle Corporation 24.45-b08) 
OS:   Mac OS X 10.10.2 x86_64 

回答

3

archives組態包含來自所有配置的所有工件。我相信混淆來自於這樣一個事實,即如果您願意,您也可以直接將構件添加到archives配置中。在這種情況下,uploadArchives任務將始終上傳所有已聲明的工件。如果你想上傳你的工件的一個子集,那麼你應該調用upload<<ConfigurationName>>任務。

相關問題