从springBoots的bootJar gradle任务中排除特定的依赖项 [英] Exclude a specific dependency from springBoots `bootJar` gradle task

查看:84
本文介绍了从springBoots的bootJar gradle任务中排除特定的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从springBoots bootJar gradle任务中排除特定的依赖关系(类似于maven中提供的作用域).

I need to exclude a specific dependency from springBoots bootJar gradle task (similar to the provided scope in maven).

我尝试了自定义配置,但是dependency-which-should-not-be-in-bootJar仍包含在生成的jar中.

I tried a custom configuration, but the dependency-which-should-not-be-in-bootJar is still included in the resulting jar.

configurations{
    provided
    implementation.extendsFrom provided
}

dependencies {
    // ...
    provided "dependency-which-should-not-be-in-bootJar"
}

jar {
    from configurations.compile - configurations.provided
    from configurations.runtime
}

bootJar {
    from configurations.compile - configurations.provided
    from configurations.runtime
    launchScript()
}

推荐答案

您实际上可以使用 compileOnly 作为对gradle> 2.12的依赖项

You can actually use compileOnly for your dependency with gradle > 2.12

dependencies {
     // ...
     compileOnly "dependency-which-should-not-be-in-bootJar"
}

您仍然可以在测试和运行时使用它,但是在最终构建的jar中则没有.

You will still have it for test + runtime, but not in the final built jar.

这篇关于从springBoots的bootJar gradle任务中排除特定的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆