gpt4 book ai didi

java - Gradle插件生成pom.xml

转载 作者:行者123 更新时间:2023-11-30 06:28:19 25 4
gpt4 key购买 nike

我用过gradle plugin to generate pom.xml .

我添加到的以下相应文档可能会项目到 build.gradle 文件中进行下一步更改:

task writePom {
doLast {
pom {
project {
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 writePom ,结果我在项目根目录中生成了 pom.xml

问题是我无法使用 pom.xml 构建项目,因为:

> maven clean install

[ERROR] /Users/XXX/Documents/projects/workspace/THE_PROJECT/src/main/java/CLASS_PACKAGE/THE_CLASS.java:[45,38] diamond operator is not supported in -source 1.5

(使用 -source 7 或更高版本来启用钻石运算符)

问题原因完全清楚。我的 pom.xml 应该使用有效的 java 版本,但其中未生成 java 版本。

我应该如何配置插件(对于gradle)来生成具有指定java版本的pom.xml

添加更多详细信息

构建.gradle

buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath group: 'pl.allegro.tech.build', name: 'axion-release-plugin', version: '1.7.1'
classpath 'org.hidetake:gradle-ssh-plugin:1.1.3'
}
}

plugins {
id "nebula.provided-base" version "3.0.3"
}

apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'groovy'
apply plugin: 'osgi'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'jacoco'
apply plugin: 'signing'
apply plugin: 'pl.allegro.tech.build.axion-release'
apply plugin: 'nebula.optional-base'
apply from: 'gradle/dist.gradle'

group = 'org.mnode.ical4j'
description = '''
A Java library for reading and writing iCalendar (*.ics) files
'''

sourceCompatibility = 1.7
targetCompatibility = 1.7
ext {
slf4jVersion = '1.7.10'
}

repositories {
mavenCentral()
}

dependencies {
api "org.slf4j:slf4j-api:$slf4jVersion",
'commons-codec:commons-codec:1.9',
'org.apache.commons:commons-lang3:3.3.2',
'org.apache.commons:commons-collections4:4.0',
'org.threeten:threetenbp:1.3.3'

compile 'org.codehaus.groovy:groovy-all:2.3.2', optional

compileOnly 'biz.aQute.bnd:bndlib:2.3.0'

testImplementation 'org.codehaus.groovy:groovy-all:2.3.2',
'org.spockframework:spock-core:0.7-groovy-2.0',
'commons-io:commons-io:2.4',
'org.ccil.cowan.tagsoup:tagsoup:1.2.1',
"org.slf4j:slf4j-log4j12:$slf4jVersion"
}

jacocoTestReport {
reports {
xml.enabled true
html.enabled false
}
}

javadoc {
if (JavaVersion.current().isJava8Compatible()) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from 'build/docs/javadoc'
}

task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}

jar {
manifest {
instruction 'Import-Package', 'groovy.*;resolution:=optional, org.codehaus.groovy*;resolution:=optional, *'
}
}

artifacts {
archives jar
archives javadocJar
archives sourcesJar
}

signing {
required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}

scmVersion {
tag {
prefix = 'ical4j'
}
versionCreator 'versionWithBranch'
branchVersionCreator = [
'master': 'simple'
]
}
version = scmVersion.version

ext {
isReleaseVersion = !version.endsWith("SNAPSHOT")
}

task writePom {
doLast {
pom {
project {
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")
}
}

最佳答案

您可以使用目标命令指定Java版本:

targetCompatibility = '1.7'

尝试使用以下代码:

apply plugin: 'java'
compileJava {
sourceCompatibility = '1.7'
}

有关更多信息,请访问此帖子:

how specify the required java version in a gradle build?

关于java - Gradle插件生成pom.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46649837/

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