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

时间:2015-02-06 15:38:28

标签: upload gradle artifact

我很困惑为什么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的文物?
  3. 由于

    $ 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
    

1 个答案:

答案 0 :(得分:4)

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