2017-06-08 20 views
0

私は、JavaベースのMavenプラグインを持つmavenプロジェクトをgradleに移行する作業をしています。このプラグインは、maven-plugin-pluginを使用しており、目標記述子とhelpmojoを持っています。gradleでmavenプラグイン記述子(plugin.xml)を生成できますか?

<build> 
    <plugins> 
     <plugin> 
     <artifactId>maven-plugin-plugin</artifactId> 
     <version>3.4</version> 
     <configuration> 
     </configuration> 
     <executions> 
      <execution> 
      <id>default-descriptor</id> 
      <goals> 
       <goal>descriptor</goal> 
      </goals> 
      <phase>process-classes</phase> 
      </execution> 
      <execution> 
      <id>help-descriptor</id> 
      <goals> 
       <goal>helpmojo</goal> 
      </goals> 
      <phase>process-classes</phase> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 

私はGradleの中でこれらの目標を実行することができ、または私はGradleの中で私のJavaベースのMavenプラグインを書き換える必要があります方法はありますか?

+0

Gradleのサポートはありません。これを行うthirdpartyプラグインは認識していません。 –

+0

Gradleを使ってMavenプラグインプロジェクトをビルドする理由はわかりません。 – Tome

答えて

0

このファイルをgradleで作成するには、build.gradleでこのタスクコードを実行します。このコードは一時的にpom.xmlを生成し、一時的なpomでmavenを実行し、plguin.xmlファイルを生成します。最後に(doLastで)、タスクはファイルをMETA-INF/maven /ディレクトリにコピーします。

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" 
    } 
} 
+0

ねえ。私はあなたの答えを試して、それは私に "範囲外のインデックス"エラーを与える。助けてくれてありがとう、しかし、私はgradleのmavenプラグインを書き直すつもりだと思う – ionut

関連する問題