我导入了一个与我的同事运行良好的项目,但是,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 dependencies --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 (*)
答案 0 :(得分:1)
您可以使用gradle dependencies --configuration runtime
来确定不同版本的包含方式。稍后,您可以从不需要的组(或工件)中排除依赖关系,并将所需的版本定义为依赖关系。
compile('group:artifact:version') {
exclude group: 'org.json', module: 'json'
}
compile("org.json:json:requiredVersion")