From a9d257f27c323c3ea3b27b224b5862a88276a855 Mon Sep 17 00:00:00 2001 From: qibaoguang Date: Tue, 14 Apr 2015 00:34:08 +0800 Subject: [PATCH] Update 73.5. Create a non-executable JAR with exclusions.md --- ...Create a non-executable JAR with exclusions.md | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/IX. ‘How-to’ guides/73.5. Create a non-executable JAR with exclusions.md b/IX. ‘How-to’ guides/73.5. Create a non-executable JAR with exclusions.md index e69de29..57ec974 100644 --- a/IX. ‘How-to’ guides/73.5. Create a non-executable JAR with exclusions.md +++ b/IX. ‘How-to’ guides/73.5. Create a non-executable JAR with exclusions.md @@ -0,0 +1,65 @@ +### 73.5. 使用排除创建不可执行的JAR + +如果你构建的产物既有可执行的jar和非可执行的jar,那你常常需要为可执行的版本添加额外的配置文件,而这些文件在一个library jar中是不需要的。比如,application.yml配置文件可能需要从非可执行的JAR中排除。 + +下面是如何在Maven中实现: +```xml + + + + org.springframework.boot + spring-boot-maven-plugin + + exec + + + + maven-jar-plugin + + + exec + package + + jar + + + exec + + + + package + + jar + + + + true + + application.yml + + + + + + + +``` +在Gradle中,你可以使用标准任务的DSL(领域特定语言)特性创建一个新的JAR存档,然后在bootRepackage任务中使用withJarTask属性添加对它的依赖: +```gradle +jar { + baseName = 'spring-boot-sample-profile' + version = '0.0.0' + excludes = ['**/application.yml'] +} + +task('execJar', type:Jar, dependsOn: 'jar') { + baseName = 'spring-boot-sample-profile' + version = '0.0.0' + classifier = 'exec' + from sourceSets.main.output +} + +bootRepackage { + withJarTask = tasks['execJar'] +} +```