从 springBoots `bootJar` gradle 任务中排除特定依赖项

2024-02-03

我需要从 spring Boots 中排除特定依赖项bootJargradle任务(类似于maven中提供的范围)。

我尝试了自定义配置,但是dependency-which-should-not-be-in-bootJar仍然包含在生成的 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()
}

我也得到了答复安迪·威尔金森 https://stackoverflow.com/users/1384297/andy-wilkinson在 Spring Boot gitter 通道中,其工作原理略有不同,但设法实现相似的效果。

configurations {
    custom
    runtime.extendsFrom custom
}

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-web'
    custom 'com.h2database:h2'
}

bootJar {
    exclude {
        configurations.custom.resolvedConfiguration.files.contains(it.file)
    }
}

谢谢你安迪 =)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 springBoots `bootJar` gradle 任务中排除特定依赖项 的相关文章

随机推荐