[英]Could not get unknown property "runtime" Gradle 7.0
I switched to gradle 7.0 recently and now cannot build my projects jar, with the error我最近切换到 gradle 7.0,现在无法构建我的项目 jar,出现错误
Could not get unknown property 'runtime' for configuration container of type org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.
无法为 org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer 类型的配置容器获取未知属性“运行时”。 `
`
Here is my build.gradle:这是我的 build.gradle:
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'
repositories {
mavenCentral()
}
dependencies {
implementation group: 'org.glassfish.jersey.containers', name: 'jersey-container-servlet-core', version: '2.7'
implementation group: 'org.eclipse.jetty.aggregate', name: 'jetty-all', version: '9.3.0.M1'
//
implementation 'javax.xml.bind:jaxb-api:2.3.0'
// testImplementation group: 'junit', name: 'junit', version: '4.11'
implementation group: 'org.json', name: 'json', version: '20200518'
implementation group: 'com.jolbox', name: 'bonecp', version: '0.8.0.RELEASE'
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.22'
implementation group: 'com.fasterxml.jackson.jaxrs', name: 'jackson-jaxrs-json-provider', version: '2.12.0'
implementation "org.slf4j:slf4j-simple:1.7.9"
}
version = '1.0'
jar {
manifest {
attributes(
'Main-Class': 'classes.RestServer',
)
}
}
task fatJar(type: Jar) {
manifest.from jar.manifest
classifier = 'all'
from {
configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
} {
exclude "META-INF/.SF"
exclude "META-INF/.DSA"
exclude "META-INF/*.RSA"
}
with jar
}
artifacts {
archives fatJar
}
Gradle removed the runtime configuration after Gradle 6.x. Gradle 在 Gradle 6.x 之后删除了运行时配置。
You can either change your fatJar
task in build.gradle
to refer to runtimeConfiguration
(as per the Java plugin documentation ):您可以更改 build.gradle 中的
fatJar
任务以runtimeConfiguration
build.gradle
根据Java 插件文档):
task fatJar(type: Jar) {
manifest.from jar.manifest
classifier = 'all'
from {
// change here: runtimeClasspath instead of runtime
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
} {
exclude "META-INF/.SF"
exclude "META-INF/.DSA"
exclude "META-INF/*.RSA"
}
with jar
}
Alternatively use a plugin that deals with fat jar building for you.或者使用为您处理胖 jar 构建的插件。 I've tried Shadow a few years ago.
几年前我尝试过Shadow 。 This should also take care of files with the same names from different jars (like
META-INF/LICENSE
) that you may run into with your approach.这还应该处理来自不同 jar 的具有相同名称的文件(例如
META-INF/LICENSE
),您可能会在您的方法中遇到这些文件。
Support for runtime
configuration has been stopped gradle-7.0
, so configurations.runtime
is not working.对
runtime
配置的支持已停止gradle-7.0
,因此configurations.runtime
不起作用。
Task copyAllDependencies
worked for me in gradle-7.0
.任务
copyAllDependencies
在gradle-7.0
中为我工作。
Here is the example to copy dependencies into ${buildDir}/output/libs
:这是将依赖项复制到
${buildDir}/output/libs
的示例:
Add following to build.gradle
.将以下内容添加到
build.gradle
。
task copyAllDependencies(type: Copy) {
from configurations.compileClasspath
into "${buildDir}/output/libs"
}
build.dependsOn(copyAllDependencies)
I hope it helps.我希望它有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.