2017-09-21 6 views
0

난 gradle 3.5 및 maven 플러그인을 사용하고 있습니다.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 파일을 생성

+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")