为什么 uploadArchives 从其他配置上传工件?

Why uploadArchives uploads artifacts from other configurations?

我很困惑为什么 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

其中有两个问题:

  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

archives 配置包含来自所有配置的所有工件。我相信混淆来自这样一个事实,即如果需要,您也可以将工件直接添加到 archives 配置中。在这种情况下,uploadArchives 任务将始终上传所有声明的工件。如果你想上传你的工件的一个子集,那么你应该调用 upload<<ConfigurationName>> 任务。