使用GradleMaven插件时如何设置java目标和源版本?
我正在为gradle使用Gradle3.5和maven插件 我有一个生成pom.xml的任务,由于源和目标版本的java,生成的pom是错误的 这为1.5生成了pom.xml(错误): 这是添加使用GradleMaven插件时如何设置java目标和源版本?,java,maven,gradle,build.gradle,maven-plugin,Java,Maven,Gradle,Build.gradle,Maven Plugin,我正在为gradle使用Gradle3.5和maven插件 我有一个生成pom.xml的任务,由于源和目标版本的java,生成的pom是错误的 这为1.5生成了pom.xml(错误): 这是添加build对象时的输出错误: * What went wrong: Execution failed for task ':createPom'. > No such property: _SCRIPT_CLASS_NAME_ for class: org.apache.maven.model.Mo
build
对象时的输出错误:
* 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
我就是这样解决目标和源问题的:
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'
}
}
}
}
这样我就可以设置属性了
如果您确实需要自定义构建
,您将无法以相同的方式声明它,因为负责它的插件。这是您可以做到的:
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")
当您尝试构建时,是否收到来自gradle的错误消息?
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'
}
}
}
}
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")