2012-06-26 141 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