【发布时间】:2012-06-26 14:18:07
【问题描述】:
我正在考虑迁移到 Gradle。不过,我确实有一些 Maven 插件需要在可预见的未来得到支持。
有没有办法使用 Gradle 构建 Maven 插件?
【问题讨论】:
标签: maven maven-plugin gradle
我正在考虑迁移到 Gradle。不过,我确实有一些 Maven 插件需要在可预见的未来得到支持。
有没有办法使用 Gradle 构建 Maven 插件?
【问题讨论】:
标签: maven maven-plugin gradle
Here's something 对我有用:
"install.repositories.mavenInstaller.pom.writeTo( 'pom.xml' )"
"mvn org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor"
这样"build/classes/main/META-INF/maven/plugin.xml" 被创建,然后由jar 任务正确打包,这就是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() }
【讨论】:
我不知道允许构建 Maven 插件的第三方 Gradle 插件。一种可能性是调用 Maven 来完成部分工作(特别是元数据生成)。可以即时创建必要的 POM。另一种可能性是将元数据提交到源代码管理并手动更新它(可能在需要时通过运行 Maven)。最后但同样重要的是,您可以编写一些代码在 Gradle 端执行元数据生成,可能重用一些 Maven 代码。
【讨论】:
我发现了这个可以用来创建 Maven 插件的 Gradle 插件 Maven Plugin Builder Gradle Plugin 但我还没有让它工作
【讨论】:
目前不支持该功能,但它在 development roadmap 上。每隔一段时间检查一下roadmap dashboard,看看状态是否发生了变化。
【讨论】: