0

我不确定这是否可行,但想针对该问题获得一些评论/解决方案。

我正在创建一个新的依赖项com.example:app-dep:1.0.1,将用作com.example:app依赖compile项。

app-depio.undertow:undertow-core:2.0.1.Final在项目中有一个我不想要的依赖com.example:app项,因为我排除了com.example:app-dep相关的类文件,undertow因为该类需要开发时间但在生产中不需要。

当我添加com.example:app-dep:1.0.1时,com.example:app我想排除io.undertow:undertow-core:2.0.1.Final.

但我想控制它com.example:app-dep:1.0.1可能在未来启用。

我试过的一些gradle

试一试

应用程序-dep - build.gradle

dependencies {
  implementation('io.undertow:undertow-core:2.0.1.Final') {
    transitive = true
  }
  implementation('io.undertow:undertow-servlet:2.0.1.Final') {
    transitive = false
  }
}
jar {
    from sourceSets.main.allSource
    excludes = ['com/example/ExampleServer**', 'public']
}

使用bootRepackage的生产应用程序spring-boot-gradle-pluginbuild.gradle

buildscript {
  dependencies {
    classpath "org.springframework.boot:spring-boot-gradle-plugin:1.5.12.RELEASE"
  }
}
dependencies {
  compile 'com.example:app-dep:1.0.1'
}

io.undertow:undertow-core:2.0.1.Final输出:仍在生产 spring-boot jar 中提取和添加

尝试 2

使用配置文件

dependencies {
    compile 'org.apache.commons:commons-lang3:3.4'
    testCompile 'org.mockito:mockito-core:3.1.0'
    testCompile 'org.powermock:powermock-module-junit4:1.6.6'
    testCompile 'org.powermock:powermock-api-mockito:1.6.6'
    if(isDev) {
        implementation 'io.undertow:undertow-core:2.0.1.Final'
    }
}

输出:类里面app-dep抛出编译错误,当我这样做时说以下内容./gradlew build

Undertow 服务器 = Undertow.builder().addHttpListener(8081, "localhost").setHandler(routingHandler).build(); ^ 符号:变量 Undertow 位置:类 ExampleServer 26 错误

我能做什么但我不想

在生产应用程序 build.gradle

dependencies {
  compile('com.example:app-dep:1.0.1') {
    exclude(module: 'com.example.app-dep')
  }
}

因为我想控制它app-dep

4

0 回答 0