java - 无法排除 jar 内的依赖项

标签 java intellij-idea gradle build.gradle

我有一个项目 (B),它编译本地 jar (A)。我需要排除 jar 内的依赖项 (A),但在构建 jar 时我无法做到这一点。我可以按照自己的意愿构建 jar,但我必须在其中包含这些依赖项,并且只将它们排除在项目 B 中。

这是项目A的build.gradle jar:

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'

repositories {
    mavenCentral()
}

jar {
    baseName = 'test'
    version =  '0.1.0'

    manifest {
        attributes ("Main-Class": "Main")
    }
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.4.0.RELEASE") // I need this excluded later
    compile("org.springframework.boot:spring-boot-starter-jetty:1.4.0.RELEASE") // I need this excluded later
    /*
    some other dependencies here
    */
}

这是项目 B 的 build.gradle:

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'

repositories {
    mavenCentral()
    flatDir(dirs: "lib")
}

sourceCompatibility = 1.8

dependencies {
   compile ':test:0.1.0' // this is the jar I need to exclude some things from

   compile("org.springframework.boot:spring-boot-starter-web:1.4.0.RELEASE")
   compile("org.springframework.boot:spring-boot-starter-jetty:1.4.0.RELEASE")
}

似乎使用常规排除子句不起作用

compile (':test:0.1.0') {
    exclude group: 'org.springframework.boot' // doesn't work
}

任何帮助将不胜感激。

最佳答案

我从 here 得到了答案。显然,不可能从文件存储库中读取 group 等属性。我最终将我的依赖项发布到私有(private)存储库( tutorial) 并从那里导入。

关于java - 无法排除 jar 内的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39011017/

相关文章:

java - 如何配置 IntelliJ Java 代码样式,以便在长时间优先于链式方法调用时包装赋值的右手

scalafx + intellij : NoClassDefFoundError: javafx/scene/shape/CullFace

java - Sonar 跳过集成测试

使用 JaCoCo Gradle 插件的 Android 测试代码覆盖率

JDK 1.8.0_161 中的 Java Mission Control 在 Mac OS X 上启动时卡住

java - 如何在 java 中修复未闭合标记的 XML

java - Jsp运行在Servlet代码下吗?

Java HashMap 先按值再按键排序

gradle - 告诉 IntelliJ 为 Gradle 制作 1 个单个模块而不是多个模块

android - 更新 SDK 工具和播放服务库后构建失败