2017-09-21 6 views
0

私はgradle 3.5とmavenプラグインをgradleに使用しています。gradle mavenプラグインを使用しているときにJavaターゲットとソースバージョンを設定する方法は?

私はpom.xmlを生成するタスクを持っていますが、生成されるpomは、ソースとターゲットバージョンのjavaのために間違っています。失敗

task createPom << { 
    pom { 
     project { 
      groupId 'com.domain.api' 
      artifactId 'gs-gradle' 
      version '0.1.0' 
      inceptionYear '2008' 
      licenses { 
       license { 
        name 'The Apache Software License, Version 2.0' 
        url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 
        distribution 'repo' 
       } 
      } 
     } 
    }.writeTo("pom.xml") 
} 

このgradle makePom作業を行います:buildオブジェクトを追加するときにこれは出力誤差がある

task createPom << { 
    pom { 
     project { 
      groupId 'com.domain.api' 
      artifactId 'gs-gradle' 
      version '0.1.0' 
      build { 
       plugins { 
        plugin { 
         groupId 'org.apache.maven.plugins' 
         artifactId 'maven-compiler-plugin' 
         version '3.7.0' 
         configuration { 
          source '1.8' 
          target '1.8' 
         } 
        } 
       } 
      } 
      inceptionYear '2008' 
      licenses { 
       license { 
        name 'The Apache Software License, Version 2.0' 
        url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 
        distribution 'repo' 
       } 
      } 
     } 
    }.writeTo("pom.xml") 
} 

これは、1.5(間違った)のためのpom.xmlを生成しました

* What went wrong: 
Execution failed for task ':createPom'. 
> No such property: _SCRIPT_CLASS_NAME_ for class: org.apache.maven.model.Model 

* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 

BUILD FAILED 
+0

あなたが試してビルドするとエラーメッセージが表示されますか? – dave

答えて

0

これは私がターゲットとソースの問題を解決した方法です:

pom { 
    project { 
     groupId 'com.domain.api' 
     artifactId 'gs-gradle' 
     version '0.1.0' 
     properties { 
      project { 
       build { 
        sourceEncoding 'UTF-8' 
       } 
      } 
      maven { 
       compiler { 
        source '1.8' 
        target '1.8' 
       } 
      } 
     } 

     inceptionYear '2008' 
     licenses { 
      license { 
       name 'The Apache Software License, Version 2.0' 
       url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 
       distribution 'repo' 
      } 
     } 
    } 
} 

このようにして、プロパティを設定できました。

実際にbuildをカスタマイズする必要がある場合は、それを担当するプラグインのために同じ方法で宣言することはできません。これはあなたができる方法です:

pom { 
    project { 
     groupId 'com.domain.api' 
     artifactId 'gs-gradle' 
     version '0.1.0' 
     properties { 
      project { 
       build { 
        sourceEncoding 'UTF-8' 
       } 
      } 
      maven { 
       compiler { 
        source '1.8' 
        target '1.8' 
       } 
      } 
     } 

     inceptionYear '2008' 
     licenses { 
      license { 
       name 'The Apache Software License, Version 2.0' 
       url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 
       distribution 'repo' 
      } 
     } 
    } 
}.withXml { 
    asNode().appendNode('build').appendNode('plugins').with { 
     appendNode('plugin').with { 
      appendNode('groupId', 'org.springframework.boot') 
      appendNode('artifactId', 'spring-boot-maven-plugin') 
      appendNode('version', "${springBootVersionDef}") 
      appendNode('executions').appendNode('execution').appendNode('goals').with { 
       appendNode('goal', 'repackage') 
      } 
     } 
     appendNode('plugin').with { 
      appendNode('groupId', 'org.apache.maven.plugins') 
      appendNode('artifactId', 'maven-jar-plugin') 
      appendNode('version', "3.0.2") 
      appendNode('configuration').appendNode('archive').appendNode('manifest').with { 
       appendNode('addClasspath', "true") 
       appendNode('classpathPrefix', "lib/") 
       appendNode('mainClass', "com.domain.api.Application") 
      } 
     } 
    } 
}.writeTo("pom.xml") 
関連する問題