简体   繁体   English

无法获取未知属性“运行时”Gradle 7.0

[英]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 .任务copyAllDependenciesgradle-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.

相关问题 无法在Gradle中获得任务的未知属性? - Could not get unknown property for task in Gradle? 无法获取 org.gradle.api.internal.artifacts.configurations 类型的配置容器的未知属性“运行时” - Could not get unknown property 'runtime' for configuration container of type org.gradle.api.internal.artifacts.configurations Gradle Build Error无法获得未知属性supportVersion - Gradle Build Error Could not get unknown property supportVersion Gradle:无法在 Intellij 中设置未知属性“classDumpFile” - Gradle: could not set unknown property 'classDumpFile' in Intellij 无法在 Gradle 中设置未知属性“applicationDefaultJvmArgs” - Could not set unknown property 'applicationDefaultJvmArgs' in Gradle 错误:Gradle 同步失败:无法为 DefaultConfig_Decorated 获取未知属性“API_KEY” - ERROR: Gradle sync failed: Could not get unknown property 'API_KEY' for DefaultConfig_Decorated Android Studio:“无法获得类型为 org.gradle.api.Project 的项目的未知属性‘VERSION_NAME’” - Android Studio : “Could not get unknown property 'VERSION_NAME' for project of type org.gradle.api.Project” 无法为org.gradle.api.Project类型的根项目“MyApplication3”获取未知属性“删除” - Could not get unknown property 'Delete' for root project 'MyApplication3' of type org.gradle.api.Project 无法为 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 类型的 object 获取未知属性“实现” - Could not get unknown property 'implementation' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 错误:(134, 0) 无法为 org.gradle.api.internal.FactoryNamedDomainObjectContainer 类型的 SigningConfig 容器获取未知属性“释放”。 - Error:(134, 0) Could not get unknown property 'release' for SigningConfig container of type org.gradle.api.internal.FactoryNamedDomainObjectContainer.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM