java - 如何去除gradle中的重复依赖?

标签 java gradle build.gradle gradlew

我在我的 gradle 脚本中使用依赖项部分,但我认为我正在脚本中创建依赖项的重复项。我在编译时和运行时都需要依赖项。我是否需要将依赖项定义为编译和运行时。 因为对于运行时我的脚本具有以下逻辑

runtime.configuration 这样我就可以将所有 jar 文件放入 lib 文件夹

我可以在一个部分中完成这两件事吗?我的意思是我只需要一个依赖部分编译或运行时。

请提出建议

dependencies {
        compile group: 'com.rohit.singh', name: 'common', version:'4.+'
        compile group: 'com.rohit.singh', name: 'LicenseVerifier', version:'4.+'
       compile group: 'com.rohit.singh', name: 'MegNativeJNI', version: '4.+', ext: 'so'
       compile group: 'com.rohit.singh', name: 'NativeJNI', version: '4.+', ext: 'so'
        compile(group: 'com.operasolutions', name: 'RiskAnalytics', version:'1.1') {
    exclude(module: 'jyson')
        }
        compile group: 'org.springframework', name: 'spring-context', version:'3.2.5.RELEASE'
        compile group: 'org.springframework', name: 'spring-beans', version:'3.2.5.RELEASE'
        compile group: 'org.springframework', name: 'spring-core', version:'3.2.5.RELEASE'
        compile group: 'org.springframework', name: 'spring-aop', version:'3.2.5.RELEASE'
        compile group: 'org.springframework', name: 'spring-expression', version:'3.2.5.RELEASE'
        compile group: 'org.apache.commons', name: 'commons-collections4', version:'4.0'
        compile group: 'commons-io', name: 'commons-io', version:'2.4'
        compile group: 'net.sf.supercsv', name: 'super-csv-dozer', version:'2.1.0'
        compile group: 'net.sf.supercsv', name: 'super-csv', version:'2.1.0'
        compile group: 'org.aspectj', name: 'aspectjtools', version:'1.6.2'
        compile group: 'org.python', name: 'jython-standalone', version:'2.5.3'
        compile group: 'com.google.code.gson', name: 'gson', version:'1.7.2'
        compile group: 'log4j', name: 'log4j', version:'1.2.16'
        compile group: 'com.xhaus', name: 'jyson', version:'1.0.2'
        compile group: 'com.google.guava', name: 'guava', version:'17.0'
        compile group: 'com.jamonapi', name: 'jamon', version:'2.4'
        compile group: 'ch.qos.logback', name: 'logback-classic', version:'1.1.1'
        compile group: 'ch.qos.logback', name: 'logback-core', version:'1.1.1'
        compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.6'
        compile group: 'org.codehaus.mojo', name: 'properties-maven-plugin', version:'1.0-alpha-2'
        compile group: 'args4j', name: 'args4j', version:'2.0.28'
        compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version:'1.9.5'
        testCompile group: 'junit', name: 'junit', version:'4.11'
        testCompile group: 'org.mockito', name: 'mockito-all', version:'1.9.5'
    }
    dependencies {
        runtime group: 'com.rohit.singh', name: 'engine-common', version:'4.+'
        runtime group: 'com.rohit.singh', name: 'engine-LicenseVerifier', version:'4.+'
       runtime group: 'com.rohit.singh', name: 'MegNativeJNI', version: '4.+', ext: 'so'
      runtime group: 'com.rohit.singh', name: 'NativeJNI', version: '4.+', ext: 'so'
      runtime (group: 'com.operasolutions', name: 'RiskAnalytics', version:'1.1') {
      exclude(module: 'jyson')
        }
        runtime group: 'org.springframework', name: 'spring-context', version:'3.2.5.RELEASE'
        runtime group: 'org.springframework', name: 'spring-beans', version:'3.2.5.RELEASE'
        runtime group: 'org.springframework', name: 'spring-core', version:'3.2.5.RELEASE'
        runtime group: 'org.springframework', name: 'spring-aop', version:'3.2.5.RELEASE'
        runtime group: 'org.springframework', name: 'spring-expression', version:'3.2.5.RELEASE'
        runtime group: 'org.apache.commons', name: 'commons-collections4', version:'4.0'
        runtime group: 'commons-io', name: 'commons-io', version:'2.4'
        runtime group: 'net.sf.supercsv', name: 'super-csv-dozer', version:'2.1.0'
        runtime group: 'net.sf.supercsv', name: 'super-csv', version:'2.1.0'
        runtime group: 'org.aspectj', name: 'aspectjtools', version:'1.6.2'
        runtime group: 'org.python', name: 'jython-standalone', version:'2.5.3'
        runtime group: 'com.google.code.gson', name: 'gson', version:'1.7.2'
        runtime group: 'log4j', name: 'log4j', version:'1.2.16'
        runtime group: 'com.xhaus', name: 'jyson', version:'1.0.2'
        runtime group: 'com.google.guava', name: 'guava', version:'17.0'
        runtime group: 'com.jamonapi', name: 'jamon', version:'2.4'
        runtime group: 'ch.qos.logback', name: 'logback-classic', version:'1.1.1'
        runtime group: 'ch.qos.logback', name: 'logback-core', version:'1.1.1'
        runtime group: 'org.slf4j', name: 'slf4j-api', version:'1.7.6'
        runtime group: 'org.codehaus.mojo', name: 'properties-maven-plugin', version:'1.0-alpha-2'
        runtime group: 'args4j', name: 'args4j', version:'2.0.28'
        runtime group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version:'1.9.5'
       }

最佳答案

您已经在编译范围中定义了依赖项。无需为运行时定义它们。编译范围依赖项将在运行时自动可用。

您还可以将编译依赖项放入 lib 文件夹并排除任何不需要的依赖项。但我想知道是否有任何依赖关系需要排除,以及是否值得为其构建逻辑。

我建议让您的构建脚本尽可能简单。

关于java - 如何去除gradle中的重复依赖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30283320/

相关文章:

java - 从不拥有它的线程解锁锁,或重新设计以避免这种情况?

android - Gradle 任务 jacoco 报告生成空的 html 报告文件(未指定类文件)

java - 错误 : Could not find method jcenter() for arguments [] on repository container

gradle - 在Gradle中配置任意对象

android - 将gradle从3.4升级到3.5会在生成的DataBindingClasses中抛出 “error: cannot find symbol class”和 “error: package … does not exist”

java - 在 fragment 布局中创建动态 View 时出现问题

java - 全屏 TOPMOST 窗口

java - 如何保护自己免受动态查询中的 SQL 注入(inject)攻击?

java - 构建spring框架源码遇到错误

android - 添加核心 ktx 后 Gradle 构建失败