gpt4 book ai didi

maven-2 - 为 gradle 生成的 Maven pom 设置编译器级别

转载 作者:行者123 更新时间:2023-12-03 03:41:04 24 4
gpt4 key购买 nike

我使用 gradle 作为项目依赖管理器,但由于我更喜欢​​ netbeans 并且找不到与 maven 的 native 集成,因此我将 gradle 生成的默认 pom 复制为 pom.xml。但是如何设置源和目标级别?

我的 build.gradle 看起来像

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

targetCompatibility=1.6
sourceCompatibility=1.6

在我跑之后
gradle install

并检查 build/poms/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 的特定部分。我找到了他们配置许可证、开发人员资料等的所有示例,但没有找到插件规范。

最佳答案

我花了一段时间才弄清楚。就像彼得上面说的那样,您可以添加该部分。说起来容易做起来难,至少对我来说。

幸运的是,spring 使用的是 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'
}
}
}
}
}

关于maven-2 - 为 gradle 生成的 Maven pom 设置编译器级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9672606/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com