使用Gradle构建Maven插件

Axe*_*ine 11 gradle maven-plugin maven

我正在考虑搬到Gradle.但是,我确实有一些Maven插件需要在可预见的未来得到支持.

有没有办法使用Gradle构建Maven插件?

Evg*_*din 5

对我有用:

  • 编译插件的源代码后,生成项目的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任务正确打包,这是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() }
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢。基于此,我制作了不需要替换的以下版本:https://gist.github.com/fikovnik/ffc1fed1867bc7fa679aaf8e48f00c21 (2认同)

Ben*_*hko -1

目前该功能尚不受支持,但已在开发路线图中。每隔一段时间检查路线图仪表板以查看状态是否发生变化。