java - 相同的 build.gradle 文件获取不同版本的依赖项(org.json :json)

标签 java json spring spring-boot gradle

我导入了一个与同事一起运行良好的项目,但是,尽管我们使用相同的构建,但 gradle 依赖项 (org.json:json) 正在作为不同版本导入。 gradle 文件如下所示

我的依赖项版本是 2013 年,他们的版本是 2010 年,其中 JSONObject.getString() 函数不同,导致运行应用程序时我的计算机出现错误。

如何确保我获得与他们相同的依赖关系以及是什么导致了这种差异?

build.gradle文件如下所示:

buildscript {
    ext {
        springBootVersion = '1.5.9.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'

group = 'com.ejada'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.7

repositories {
    mavenCentral()
    mavenLocal()
    maven  {
        url 'http://repo.enonic.com/public/'
    }
}

configurations {
    providedRuntime
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    compile("org.springframework:spring-context-support")
    compile("org.springframework:spring-jdbc")
    compile files('libs/ojdbc6.jar')
    compile group: 'nl.captcha', name: 'simplecaptcha', version: '1.2.1'
    compile group: 'commons-codec', name: 'commons-codec', version: '1.9'
    compile group: 'org.antlr', name: 'stringtemplate', version: '4.0.2'
    compile("org.json:json")

    compile('com.google.code.gson:gson:2.7')

    // For XML Response
    compile('com.fasterxml.jackson.dataformat:jackson-dataformat-xml')

    compile("org.springframework.boot:spring-boot-starter-security")
    compile("org.springframework.ldap:spring-ldap-core")
    compile("org.springframework.security:spring-security-ldap")
    compile("com.unboundid:unboundid-ldapsdk")
    compile("org.springframework:spring-tx")

    compile('org.apache.directory.studio:org.apache.commons.io:2.4')

    compile("org.springframework.boot:spring-boot-devtools")
    compile group: 'com.github.ulisesbocchio', name: 'jasypt-spring-boot-starter', version: '1.4-java7'
    compile('javax.servlet:javax.servlet-api')
    compile("org.aspectj:aspectjweaver")
    compile("com.fasterxml.jackson.core:jackson-databind")

}

按照请求添加 cmd gradlew dependency --configuration runtime 的输出(下面的两台机器完全相同):

runtime - Runtime dependencies for source set 'main' (deprecated, use 'runtimeOnly ' instead).
+--- org.springframework.boot:spring-boot-starter-web: -> 1.5.9.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:1.5.9.RELEASE
|    |    +--- org.springframework.boot:spring-boot:1.5.9.RELEASE
|    |    |    +--- org.springframework:spring-core:4.3.13.RELEASE
|    |    |    \--- org.springframework:spring-context:4.3.13.RELEASE
|    |    |         +--- org.springframework:spring-aop:4.3.13.RELEASE
|    |    |         |    +--- org.springframework:spring-beans:4.3.13.RELEASE
|    |    |         |    |    \--- org.springframework:spring-core:4.3.13.RELEASE
|    |    |         |    \--- org.springframework:spring-core:4.3.13.RELEASE
|    |    |         +--- org.springframework:spring-beans:4.3.13.RELEASE (*)
|    |    |         +--- org.springframework:spring-core:4.3.13.RELEASE
|    |    |         \--- org.springframework:spring-expression:4.3.13.RELEASE
|    |    |              \--- org.springframework:spring-core:4.3.13.RELEASE
|    |    +--- org.springframework.boot:spring-boot-autoconfigure:1.5.9.RELEASE
|    |    |    \--- org.springframework.boot:spring-boot:1.5.9.RELEASE (*)
|    |    +--- org.springframework.boot:spring-boot-starter-logging:1.5.9.RELEASE
|    |    |    +--- ch.qos.logback:logback-classic:1.1.11
|    |    |    |    +--- ch.qos.logback:logback-core:1.1.11
|    |    |    |    \--- org.slf4j:slf4j-api:1.7.22 -> 1.7.25
|    |    |    +--- org.slf4j:jcl-over-slf4j:1.7.25
|    |    |    |    \--- org.slf4j:slf4j-api:1.7.25
|    |    |    +--- org.slf4j:jul-to-slf4j:1.7.25
|    |    |    |    \--- org.slf4j:slf4j-api:1.7.25
|    |    |    \--- org.slf4j:log4j-over-slf4j:1.7.25
|    |    |         \--- org.slf4j:slf4j-api:1.7.25
|    |    +--- org.springframework:spring-core:4.3.13.RELEASE
|    |    \--- org.yaml:snakeyaml:1.17
|    +--- org.springframework.boot:spring-boot-starter-tomcat:1.5.9.RELEASE
|    |    +--- org.apache.tomcat.embed:tomcat-embed-core:8.5.23
|    |    |    \--- org.apache.tomcat:tomcat-annotations-api:8.5.23
|    |    +--- org.apache.tomcat.embed:tomcat-embed-el:8.5.23
|    |    \--- org.apache.tomcat.embed:tomcat-embed-websocket:8.5.23
|    |         \--- org.apache.tomcat.embed:tomcat-embed-core:8.5.23 (*)
|    +--- org.hibernate:hibernate-validator:5.3.6.Final
|    |    +--- javax.validation:validation-api:1.1.0.Final
|    |    +--- org.jboss.logging:jboss-logging:3.3.0.Final -> 3.3.1.Final
|    |    \--- com.fasterxml:classmate:1.3.1 -> 1.3.4
|    +--- com.fasterxml.jackson.core:jackson-databind:2.8.10
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.8.0
|    |    \--- com.fasterxml.jackson.core:jackson-core:2.8.10
|    +--- org.springframework:spring-web:4.3.13.RELEASE
|    |    +--- org.springframework:spring-aop:4.3.13.RELEASE (*)
|    |    +--- org.springframework:spring-beans:4.3.13.RELEASE (*)
|    |    +--- org.springframework:spring-context:4.3.13.RELEASE (*)
|    |    \--- org.springframework:spring-core:4.3.13.RELEASE
|    \--- org.springframework:spring-webmvc:4.3.13.RELEASE
|         +--- org.springframework:spring-aop:4.3.13.RELEASE (*)
|         +--- org.springframework:spring-beans:4.3.13.RELEASE (*)
|         +--- org.springframework:spring-context:4.3.13.RELEASE (*)
|         +--- org.springframework:spring-core:4.3.13.RELEASE
|         +--- org.springframework:spring-expression:4.3.13.RELEASE (*)
|         \--- org.springframework:spring-web:4.3.13.RELEASE (*)
+--- org.springframework:spring-context-support: -> 4.3.13.RELEASE
|    +--- org.springframework:spring-beans:4.3.13.RELEASE (*)
|    +--- org.springframework:spring-context:4.3.13.RELEASE (*)
|    \--- org.springframework:spring-core:4.3.13.RELEASE
+--- org.springframework:spring-jdbc: -> 4.3.13.RELEASE
|    +--- org.springframework:spring-beans:4.3.13.RELEASE (*)
|    +--- org.springframework:spring-core:4.3.13.RELEASE
|    \--- org.springframework:spring-tx:4.3.13.RELEASE
|         +--- org.springframework:spring-beans:4.3.13.RELEASE (*)
|         \--- org.springframework:spring-core:4.3.13.RELEASE
+--- nl.captcha:simplecaptcha:1.2.1
+--- commons-codec:commons-codec:1.9
+--- org.antlr:stringtemplate:4.0.2
|    \--- org.antlr:antlr-runtime:3.3
|         \--- org.antlr:stringtemplate:3.2.1 -> 4.0.2 (*)
+--- org.json:json: -> 20140107
+--- com.google.code.gson:gson:2.7
+--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml: -> 2.8.10
|    +--- com.fasterxml.jackson.core:jackson-core:2.8.10
|    +--- com.fasterxml.jackson.core:jackson-annotations:2.8.0
|    +--- com.fasterxml.jackson.core:jackson-databind:2.8.10 (*)
|    +--- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.8.10
|    |    +--- com.fasterxml.jackson.core:jackson-core:2.8.10
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.8.0
|    |    \--- com.fasterxml.jackson.core:jackson-databind:2.8.10 (*)
|    +--- org.codehaus.woodstox:stax2-api:3.1.4
|    \--- com.fasterxml.woodstox:woodstox-core:5.0.3
|         \--- org.codehaus.woodstox:stax2-api:3.1.4
+--- org.springframework.boot:spring-boot-starter-security: -> 1.5.9.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:1.5.9.RELEASE (*)
|    +--- org.springframework:spring-aop:4.3.13.RELEASE (*)
|    +--- org.springframework.security:spring-security-config:4.2.3.RELEASE
|    |    +--- org.springframework.security:spring-security-core:4.2.3.RELEASE
|    |    |    +--- aopalliance:aopalliance:1.0
|    |    |    +--- org.springframework:spring-aop:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
|    |    |    +--- org.springframework:spring-beans:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
|    |    |    +--- org.springframework:spring-context:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
|    |    |    +--- org.springframework:spring-core:4.3.9.RELEASE -> 4.3.13.RELEASE
|    |    |    \--- org.springframework:spring-expression:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
|    |    +--- org.springframework:spring-aop:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
|    |    +--- org.springframework:spring-beans:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
|    |    +--- org.springframework:spring-context:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
|    |    \--- org.springframework:spring-core:4.3.9.RELEASE -> 4.3.13.RELEASE
|    \--- org.springframework.security:spring-security-web:4.2.3.RELEASE
|         +--- org.springframework.security:spring-security-core:4.2.3.RELEASE (*)
|         +--- org.springframework:spring-beans:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
|         +--- org.springframework:spring-context:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
|         +--- org.springframework:spring-core:4.3.9.RELEASE -> 4.3.13.RELEASE
|         +--- org.springframework:spring-expression:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
|         \--- org.springframework:spring-web:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
+--- org.springframework.ldap:spring-ldap-core: -> 2.3.2.RELEASE
|    +--- org.slf4j:slf4j-api:1.7.21 -> 1.7.25
|    +--- org.springframework:spring-beans:4.3.4.RELEASE -> 4.3.13.RELEASE (*)
|    +--- org.springframework:spring-core:4.3.4.RELEASE -> 4.3.13.RELEASE
|    \--- org.springframework:spring-tx:4.3.4.RELEASE -> 4.3.13.RELEASE (*)
+--- org.springframework.security:spring-security-ldap: -> 4.2.3.RELEASE
|    +--- org.springframework.ldap:spring-ldap-core:2.2.0.RELEASE -> 2.3.2.RELEASE (*)
|    +--- org.springframework.security:spring-security-core:4.2.3.RELEASE (*)
|    +--- org.springframework:spring-beans:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
|    +--- org.springframework:spring-context:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
|    +--- org.springframework:spring-core:4.3.9.RELEASE -> 4.3.13.RELEASE
|    \--- org.springframework:spring-tx:4.3.9.RELEASE -> 4.3.13.RELEASE (*)
+--- com.unboundid:unboundid-ldapsdk: -> 3.2.1
+--- org.springframework:spring-tx: -> 4.3.13.RELEASE (*)
+--- org.apache.directory.studio:org.apache.commons.io:2.4
|    \--- commons-io:commons-io:2.4
+--- org.springframework.boot:spring-boot-devtools: -> 1.5.9.RELEASE
|    +--- org.springframework.boot:spring-boot:1.5.9.RELEASE (*)
|    \--- org.springframework.boot:spring-boot-autoconfigure:1.5.9.RELEASE (*)
+--- com.github.ulisesbocchio:jasypt-spring-boot-starter:1.4-java7
|    \--- com.github.ulisesbocchio:jasypt-spring-boot:1.4-java7
|         \--- org.jasypt:jasypt:1.9.2
+--- javax.servlet:javax.servlet-api: -> 3.1.0
+--- org.aspectj:aspectjweaver: -> 1.8.13
+--- com.fasterxml.jackson.core:jackson-databind: -> 2.8.10 (*)
\--- org.springframework.boot:spring-boot-starter-tomcat: -> 1.5.9.RELEASE (*)

最佳答案

您可以使用gradle依赖项--configuration运行时来弄清楚如何包含不同的版本。稍后,您可以从不需要的组(或工件)中排除依赖项,并将所需的版本定义为依赖项。

 compile('group:artifact:version') {
    exclude group: 'org.json', module: 'json' 
 }
 compile("org.json:json:requiredVersion")

关于java - 相同的 build.gradle 文件获取不同版本的依赖项(org.json :json),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49358470/

相关文章:

JavaFX TreeView setRoot 导致异常

java - JDBC hive 连接字符串中使用的端口号在哪里定义?

java - springboot单元测试中无法获取resilience4j重试注解执行

Spring jdbc 'select for update'

java - 保存成功后无法更新

java - 如何在 android studio 中随机化图像?我写的代码不起作用

javascript - 无法为 Google 图表构建 json 数据表

java - 通过 Java 使用 auth token 发出 api 请求

python - 如何使用 grequest 从多个 url 打印相同的字典对象?

java - QueryDSL:从实体构建查询