2012-03-12 61 views
1

我使用gradle作爲項目依賴項管理器,但由於我更喜歡​​netbeans,並且找不到maven的本地集成,我將gradle生成的默認pom複製爲pom.xml。但是,我如何設置源和目標級別?設置編譯器級別對於Gradle生成的Maven pom

我的build.gradle看起來像

apply plugin: 'eclipse' 
apply plugin: 'maven' 
apply plugin: 'java' 

targetCompatibility=1.6 
sourceCompatibility=1.6 

我跑

gradle install 

,並檢查構建/勁歌/ POM-default.xml中它從來沒有配置這是默認的來源,也不目標水平後,到1.3

我缺乏的是maven編譯器插件配置

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
       <encoding>UTF-8</encoding> 
      </configuration> 
     </plugin> 

並且一直未能找到如何配置pom的特定部分。我已經找到了所有配置許可證,開發人員等等但不是插件規範的示例。

回答

1

您可以按照與示例「許可證和開發人員」相同的方式添加該部分。

+0

我試圖和它說'>沒有這樣的屬性:類_SCRIPT_CLASS_NAME_:org.apache.maven.model.Model'當我嘗試添加'build.plugins.plugin'成'項目'。 – BigDong 2017-09-21 07:06:51

2

花了我一段時間才弄明白。就像Peter在上面說過的,你可以只添加該部分。說起來容易做起來難,至少對我而言。

幸運的是,春天正在使用gradle,所以你有很多現實世界的例子。檢查git的樞紐

install { 
    repositories.mavenInstaller { 
     customizePom(pom, project) 
    } 
} 

def customizePom(pom, gradleProject) { 
    pom.whenConfigured { generatedPom -> 
     // respect 'optional' and 'provided' dependencies 
     gradleProject.optionalDeps.each { dep -> 
      generatedPom.dependencies.find { it.artifactId == dep.name }?.optional = true 
     } 
     gradleProject.providedDeps.each { dep -> 
      generatedPom.dependencies.find { it.artifactId == dep.name }?.scope = 'provided' 
     } 

     // eliminate test-scoped dependencies (no need in maven central poms) 
     generatedPom.dependencies.removeAll { dep -> 
      dep.scope == 'test' 
     } 

     // add all items necessary for maven central publication 
     generatedPom.project { 
      name = gradleProject.description 
      description = gradleProject.description 
      organization { 
       name = 'bajoneando' 
      } 
      build { 
       plugins { 
        plugin { 
         groupId = 'org.apache.maven.plugins' 
         artifactId = 'maven-compiler-plugin' 
         configuration { 
          source = '1.6' 
          target = '1.6' 
         } 
        } 
        plugin { 
         groupId = 'org.apache.maven.plugins' 
         artifactId = 'maven-surefire-plugin' 
         configuration { 
          includes { 
           include = '**/*Tests.java' 
          } 
          excludes { 
           exclude = '**/*Abstract*.java' 
          } 
         } 
        } 
       } 
       resources { 
        resource { 
         directory = 'src/main/java' 
         includes = ['**/*'] 
         excludes = ['**/*.java'] 
        } 
        resource { 
         directory = 'src/main/resources' 
         includes = ['**/*'] 
        } 
       } 
       testResources { 
        testResource { 
         directory = 'src/test/java' 
         includes = ['**/*'] 
         excludes = ['**/*.java'] 
        } 
        testResource { 
         directory = 'src/test/resources' 
         includes = ['**/*'] 
        } 
       } 
      } 
      developers { 
       developer { 
        id = 'lnramirez' 
        name = 'Luis Ramirez Monterosa' 
        email = '*****@gmail.com' 
       } 
      } 
     } 
    } 
}