【问题标题】:Cannot change dependencies of configuration无法更改配置的依赖关系
【发布时间】:2017-04-03 16:47:29
【问题描述】:

在我将copyBootstrap 添加到build.gradle 后,尝试运行build 任务时出现下一个错误:

FAILURE:构建失败并出现异常。

  • 出了什么问题:

配置根项目时出现问题'。 配置 ':providedCompile' 包含在依赖项解析中后,无法更改其依赖项。

如何解决这个问题?我在互联网上搜索过,但没有找到解决方案。我从this link 得到了copyBootstrap 任务。他们的目标是从org.webjars 组 jar 中提取所有内容到特定路径。

我正在使用 Gradle 3.2 和 Intellij IDEA 2016.2.5

//group 'org'
//version '1.0-SNAPSHOT'

task wrapper(type: Wrapper) {
  gradleVersion = '3.2'
  distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}


buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'org.akhikhl.gretty:gretty:1.4.0'
    }
}

repositories {
    mavenCentral()
    jcenter()
}

//apply plugin: 'java'
//apply plugin: 'eclipse-wtp'
//apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'


sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {

    //compile group: 'org.akhikhl.gretty', name: 'gretty', version: '1.4.0'


    // ********************************************************************************************************
    // SPRING FRAMEWORK, ORM Y H2DB
    // ********************************************************************************************************

    compile group: 'org.springframework', name: 'spring-webmvc', version: '4.3.4.RELEASE'
    compile group: 'org.springframework', name: 'spring-orm', version: '4.3.4.RELEASE'
    compile group: 'org.springframework', name: 'spring-jdbc', version: '4.3.4.RELEASE'
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.3.Final'


    // ********************************************************************************************************
    // JACKSON DATABIND
    // ********************************************************************************************************

    compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.4'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.4'


    // ********************************************************************************************************
    // THYMELEAF
    // ********************************************************************************************************

    compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '3.0.2.RELEASE'


    // ********************************************************************************************************
    // SERVLET
    // ********************************************************************************************************

    compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'


    // ********************************************************************************************************
    // MYSQL CONNECTOR
    // ********************************************************************************************************

    //compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5' issues with time zone
    compile 'mysql:mysql-connector-java:5.1.6'

    // ********************************************************************************************************
    // WEB RESOURCES
    // ********************************************************************************************************

    compile group: 'org.webjars', name: 'angularjs', version: '1.5.8'
    compile group: 'org.webjars', name: 'jquery', version: '2.1.4'
    compile group: 'org.webjars', name: 'bootstrap', version: '3.3.7'
    compile group: 'org.webjars', name: 'jquery-ui', version: '1.12.1'
    compile group: 'org.webjars', name: 'modernizr', version: '2.8.3'


    // ********************************************************************************************************
    // JUNIT AND SPRING TEST
    // ********************************************************************************************************

    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile group: 'org.springframework', name: 'spring-test', version: '4.3.4.RELEASE'


    // ********************************************************************************************************
    // GOOGLE DRIVE API
    // ********************************************************************************************************

    compile group: 'com.google.api-client', name: 'google-api-client', version: '1.22.0'
    compile group: 'com.google.apis', name: 'google-api-services-drive', version: 'v2-rev245-1.22.0'
    compile group: 'com.google.api-client', name: 'google-api-client-java6', version: '1.22.0'
    compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.22.0'


    // ********************************************************************************************************
    // DROPBOX API
    // ********************************************************************************************************

    compile group: 'com.dropbox.core', name: 'dropbox-core-sdk', version: '1.8.2'


    // ********************************************************************************************************
    // TWITTER API
    // ********************************************************************************************************

    compile group: 'org.twitter4j', name: 'twitter4j-core', version: '4.0.5'


//    compile group: 'org.slf4j', name: 'slf4j-mylearn.api', version: '1.7.21'
//    compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.21'

//    compile files("twitter/main/webapp/") // add this path as a classpath

}


task copyBootstrap(type: Copy) {
    into "$buildDir/static_resources"
    configurations.compile
            .files({ it.group.equals("org.webjars")})
            .each {
        from zipTree(it)
    }
}

//build.dependsOn(copyBootstrap)

task copyToLib2(type: Copy) {
    into "$buildDir/output/libs"
    from configurations.runtime
}

war {
  archiveName = 'ROOT.war'
  destinationDir = file('webapps')
}


// ********************************************************************************************************
// GRETTY SETTINGS
// ********************************************************************************************************

/* Change context path (base url). otherwise defaults to name of project */
gretty {
    port = 8081
    contextPath = ''
}

【问题讨论】:

    标签: intellij-idea gradle gretty


    【解决方案1】:

    这个问题似乎与您尝试使用的org.akhikhl.gretty 插件有关。如果我尝试使用上述 gradle 文件构建项目,我会得到以下输出:

    C:\ws\PLAYGROUND\test123>gradle wrapper --stacktrace
    Changed dependencies of configuration ':providedCompile' after it has been included in dependency resolution. This behaviour has been deprecated and is cheduled to be removed in Gradle 3.0.
    Changed dependencies of parent of configuration ':compile' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
    Changed strategy of configuration ':compile' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
    Changed dependencies of configuration ':grettyProvidedCompile' after it has been included in dependency resolution. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0.
    
    ⋮
    
    * Exception is:
    org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'test123'.
        at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:79)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:74)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:61)
        ⋮
    Caused by: org.gradle.api.InvalidUserDataException: Cannot change dependencies of configuration ':compile' after it has been resolved.
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.validateMutation(DefaultConfiguration.java:578)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$2.run(DefaultConfiguration.java:137)
        ⋮
        at org.akhikhl.gretty.GrettyPlugin$_addDependencies_closure11.doCall(GrettyPlugin.groovy:130)
        ⋮
    

    这是 gretty 插件似乎使用了 gradle 3.0 删除的功能

    不久前有人报告了issue #306,它几乎描述了您的问题。

    考虑到这样一个小项目的未解决问题的数量以及这些问题缺乏活动,我认为这个插件没有多大帮助,你可能会更好地使用不同的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2016-02-25
      • 2017-04-10
      • 2016-05-25
      • 1970-01-01
      • 2019-06-16
      相关资源
      最近更新 更多