【问题标题】:Gradle eclipse using incorrect version for dependenciesGradle eclipse 对依赖项使用不正确的版本
【发布时间】:2015-03-29 00:36:47
【问题描述】:

我正在将一个项目迁移到 gradle 以解决依赖关系,生成 eclipse 项目并构建项目,但我对 eclipse 项目的某些依赖项的版本有问题。这是项目的 build.gradle。这是一个带有子项目的 EAR。

apply plugin: 'ear'

def eclipseJbossName = 'org.eclipse.jst.server.core.container/org.jboss.ide.eclipse.as.core.server.runtime.runtimeTarget/JBoss 6.x Runtime'
def defaultEarConfig = rootDir.getAbsolutePath() + '/ear.gradle'

allprojects {
    apply plugin: 'eclipse'
    apply plugin: 'eclipse-wtp'
    apply plugin: 'idea'
    eclipse {
        classpath {
            containers eclipseJbossName
        }
    }
    repositories {
        maven {
            name = "mvnrepository"
            url = "http://mvnrepository.com/"
        }
        mavenCentral()
        maven {
            name = 'jboss'
            url = 'http://repository.jboss.org/nexus/content/groups/public/'
        }
    }
}

subprojects {
    configurations {
        provided
    }
    apply plugin: 'java'
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
    sourceSets {
        main {
            compileClasspath += configurations.provided
            compileClasspath += configurations.compile
            compileClasspath += configurations.runtime
        }
    }
}
dependencies {
    deploy (project(path: 'anEJB')) {
        transitive = false
    }
    deploy (project(path: 'anotherEJB')) {
        transitive = false
    }
    deploy (project(path: 'aWAR', configuration: 'archives')) {
        transitive = false
    }
    earlib ('commons-beanutils:commons-beanutils:1.6') {
        transitive = false
    }
    //lots of other dependencies and all with transitive=false
}
//configuration of my subprojects

当我调用gradle ear 时,它会正确构建并生成我的工件。在 EAR 根目录内的 lib 目录中,有我所有的 earlib 及其正确版本。当我调用gradle cleanEclipse eclipse 时,它会正确生成我的项目,但是当我在 eclipse 中看到构建路径时,它使用的 commons beanutils 版本不正确。它使用的是 1.8 版本。我的所有依赖项都没有发生这种情况,但还有其他人有这个问题。我已经竭尽全力不解决传递依赖关系。

【问题讨论】:

  • 抱歉,我无法重现您的问题。也许你可以为它写一个简短的复制器?您使用哪个版本的 Gradle?
  • 对我来说它适用于 Gradle 2.1 ...抱歉 ...

标签: java eclipse maven gradle ear


【解决方案1】:

您可以在 Eclipse 中用鼠标右键单击项目,然后单击属性。并选择“Java Build Path”,然后单击“Libraries”选项卡。最后删除除“Gradle Dependencies”和“JRE System Libraries”之外的所有jar。

完成。试试看。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-30
    • 2023-04-01
    • 1970-01-01
    • 2017-01-25
    • 2015-01-06
    • 2017-08-21
    • 1970-01-01
    • 2017-02-01
    相关资源
    最近更新 更多