简体   繁体   English

Gradle:解决后无法更改配置“:compile”的依赖项

[英]Gradle: Cannot change dependencies of configuration ':compile' after it has been resolved

I'm using Netbeans 8.0.2 with Gradle Support plugin 1.3.8.我将 Netbeans 8.0.2 与 Gradle Support 插件 1.3.8 一起使用。

I've added a task to generate a uber-Jar while excluding a few signature files, however when I run the task it displays an error at line 38 (the compile group line) as follows:我添加了一个任务来生成 uber-Jar,同时排除了一些签名文件,但是当我运行该任务时,它在第 38 行( compile group行)显示错误,如下所示:

apply plugin: 'java'
apply plugin: 'application'

mainClassName = 'br.com.myproject.Sample'
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
version='1.0.0'

// For DEBUG to work
ext.mainClass = mainClassName

task uniqueJar(type: Jar) {
    baseName = project.name

    from(configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }) {
        exclude "META-INF/*.SF"
        exclude "META-INF/*.DSA"
        exclude "META-INF/*.RSA"
    }

    manifest {
        attributes 'Implementation-Title': project.name,  
                'Implementation-Version': version,
                'Main-Class': mainClassName
    }
    with jar
}

repositories {
    mavenCentral()
    // You may define additional repositories, or even remove "mavenCentral()".
    // Read more about repositories here:
    //   http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:repositories
}

dependencies {
    // https://mvnrepository.com/artifact/org.eclipse.paho/org.eclipse.paho.client.mqttv3
    compile group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version: '1.1.1' // line 38


    testCompile group: 'junit', name: 'junit', version: '4.10'
}

Error message:错误信息:

Executing: gradle unique Jar Arguments: [uniqueJar, -c, D:\\NetBeansProjects\\testeMqtt\\settings.gradle]执行:gradle unique Jar 参数:[uniqueJar, -c, D:\\NetBeansProjects\\testeMqtt\\settings.gradle]

FAILURE: Build failed with an exception. FAILURE:构建失败,出现异常。

  • Where: Build file 'D:\\NetBeansProjects\\testeMqtt\\build.gradle' line: 38其中:构建文件 'D:\\NetBeansProjects\\testeMqtt\\build.gradle' 行:38

  • What went wrong: A problem occurred evaluating root project 'testeMqtt'.出了什么问题:评估根项目“testeMqtt”时出现问题。

    Cannot change dependencies of configuration ':compile' after it has been resolved.解决后无法更改配置“:compile”的依赖项。

  • Try: Run with --stacktrace option to get the stack trace.尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。 Run with --info or --debug option to get more log output.使用 --info 或 --debug 选项运行以获得更多日志输出。

BUILD FAILED构建失败

Total time: 0.102 secs总时间:0.102秒

How can I fix the uber-Jar task?如何修复 uber-Jar 任务?

Solved my issue using the Shadow gradle plugin for generating uber-Jars:使用Shadow gradle 插件生成 uber-Jars 解决了我的问题:

apply plugin: 'java'
apply plugin: 'application'

mainClassName = 'br.com.myproject.Sample'
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
version='1.0.0'

// For DEBUG to work
ext.mainClass = mainClassName

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.1'
    testCompile group: 'junit', name: 'junit', version: '4.10'
}

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
    }
}

apply plugin: 'com.github.johnrengelman.shadow'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解决后无法更改配置“:compile”的依赖项 - Cannot change dependencies of configuration ':compile' after it has been resolved Gradle Drools 6.2无法解析配置':compile'的所有依赖项 - Gradle Drools 6.2 Could not resolve all dependencies for configuration ':compile' Gradle 构建失败 [无法解析配置 ':compile' 的所有依赖项。] - Gradle build is failing [Could not resolve all dependencies for configuration ':compile'.] 具有编译依赖项的 Gradle 任务 - Gradle task with compile dependencies Gradle,使用gpg进行多项目签名。 访问“扩展”扩展名后无法配置 - Gradle, multiproject signing with gpg. Cannot configure the 'publishing' extension after it has been accessed 无法在“ Apache Tomcat”运行配置中正确显示“ Gradle Dependencies” - “Gradle Dependencies” cannot be correctly shown in 'Apache Tomcat' Run Configuration 如何解决此问题“配置'compile'已过时,并已由'implementation'和'api'代替。” - How to solve this “Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.” 信息:配置“编译”已过时,已替换为“实施”和“API” - INFO: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api' 使用两种配置编译gradle - Compile gradle with two configuration gradle的配置编译和运行时 - Configuration compile and runtime for gradle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM