2016-12-08 50 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