2016-12-08 54 views
1

我的gradle构建副本文件。我想用复制任务的输出作为Maven构件输入出版从副本任务发布工件

例如:

task example(type: Copy) { 
    from "build.gradle" // use as example 
    into "build/distributions" 
} 

publishing { 
    publications { 
     mavenJava(MavenPublication) { 
      artifact example 
     } 
    } 
} 

的Gradle,但不喜欢它:

* What went wrong: 
A problem occurred configuring project ':myproject'. 
> Exception thrown while executing model rule: PublishingPlugin.Rules#publishing(ExtensionContainer) 
    > Cannot convert the provided notation to an object of type MavenArtifact: task ':myproject:example'. 
     The following types/formats are supported: 
     - Instances of MavenArtifact. 
     - Instances of AbstractArchiveTask, for example jar. 
     - Instances of PublishArtifact 
     - Maps containing a 'source' entry, for example [source: '/path/to/file', extension: 'zip']. 
     - Anything that can be converted to a file, as per Project.file() 

为什么?

据我所知,任务示例的输出应该由Copy任务设置。我认为它可以转换为一些文件。所以它应该用作发布任务的输入,作为文件。但是错误信息告诉我我错了。

我该如何解决?

感谢

回答

4

摇篮不知道如何将Copy任务转换为MavenArtifactAbstractArchiveTaskPublishArtifact,...哪位解释错误消息。

它不知道如何将一个String转换为File,因为它是在错误信息的最后一行解释。

问题是如何强制Gradle在发布之前构建我的任务。 MavenArtifact有一个builtBy方法,这是为此!

task example(type: Copy) { 
    from "build.gradle" // use as example 
    into "build/distributions" 
} 

publishing { 
    publications { 
     mavenJava(MavenPublication) { 
      // file to be transformed as an artifact 
      artifact("build/distributions/build.gradle") { 
       builtBy example // will call example task to build the above file 
      } 
     } 
    } 
} 
+0

我一直在寻找这个答案近一个星期。救世主:) – CoderSpinoza