2012-06-26 132 views

回答

-1

此功能不支持,但它在development roadmap。每隔一段時間檢查roadmap dashboard以查看狀態是否改變。

+1

我們的重點是支持Gradle中的Maven插件的_reuse_,而不是支持_build_它們。 –

+0

我明白了。我想我誤解了這個問題。 –

+0

路線圖儀表板鏈接不再有效 – Matthew

0

我不知道允許構建Maven插件的第三方Gradle插件。一種可能性是調用Maven完成部分工作(特別是元數據生成)。必要的POM可以在飛行中創建。另一種可能性是將元數據提交給源代碼管理並手動更新(可能需要時運行Maven)。最後但並非最不重要的是,您可以編寫一些代碼來執行Gradle方面的元數據生成,可能會重用一些Maven代碼。

+0

太糟糕了,這是不計劃的。讓我們看看是否有一個好的解決方法... –

3

Here's something是爲我工作:

  • 編寫插件的源後生成項目的POM:"install.repositories.mavenInstaller.pom.writeTo('pom.xml')"
  • 補丁POM生成並提供插件的座標和正確的目標目錄
  • 運行"mvn org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor"

這種方式"build/classes/main/META-INF/maven/plugin.xml"被創建,然後由正確包裝任務,這是一個jar文件成爲Maven插件AFAIK所需的全部功能。另外,我相信,"maven-plugin-annotations"應該用在插件中。

task pluginDescriptor(type: Exec) { 
    commandLine 'mvn', '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor' 
    doFirst { 
     final File pom = project.file('pom.xml') 
     install.repositories.mavenInstaller.pom.writeTo(pom) 
     assert pom.file, "[$pom.canonicalPath] was not created" 

     pom.text = pom.text. 
      replace('<groupId>unknown</groupId>',    "<groupId>${project.group}</groupId>"). 
      replace('<artifactId>empty-project</artifactId>', "<artifactId>${project.name}</artifactId>"). 
      replace('<version>0</version>',     """ 
                   |<version>${version}</version> 
                   | <packaging>maven-plugin</packaging> 
                   | <build> 
                   | <directory>\${project.basedir}/build</directory> 
                   | <outputDirectory>\${project.build.directory}/classes/main</outputDirectory> 
                   | </build> 
                   |""".stripMargin().trim()) 
    } 
    doLast { 
     final pluginDescriptor = new File((File) project.compileGroovy.destinationDir, 'META-INF/maven/plugin.xml') 
     assert pluginDescriptor.file, "[$pluginDescriptor.canonicalPath] was not created" 
     println "Plugin descriptor file:$pluginDescriptor.canonicalPath is created successfully" 
    } 
} 

project.compileGroovy.doLast{ pluginDescriptor.execute() } 
+1

非常感謝。基於此,我提出了不需要替換的以下版本:https://gist.github.com/fikovnik/ffc1fed1867bc7fa679aaf8e48f00c21 – fikovnik