我很困惑为什么Gradle的uploadArchive
正在从其他配置上传工件。我的理解是,当您声明配置时,它将为您获取上载任务,并在被调用时将上载分配给其配置的工件。
这不是我所看到的行为:
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
有两个问题:
fooIt
会被执行?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
答案 0 :(得分:4)
archives
配置包含所有配置中的所有工件。我相信这种混淆来自于您可以根据需要将工件直接添加到archives
配置这一事实。在这种情况下,uploadArchives
任务将始终上传所有已声明的工件。如果要上传工件的子集,则应调用upload<<ConfigurationName>>
任务。