Browse Source
The Maven plugin allows spring-boot:run to be configured so that
resources are loaded from their output location rather than from
src/main/resources. This commit adds an equivalent configuration
option to the Gradle plugin. To disable source resources from being
added to the classpath in place of those in the output location
the configure the bootRun tasks like this:
bootRun {
addResources = false
}
Closes gh-2431
pull/2459/head
7 changed files with 167 additions and 20 deletions
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
/* |
||||
* Copyright 2012-2015 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.gradle; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
import org.gradle.tooling.ProjectConnection; |
||||
import org.junit.BeforeClass; |
||||
import org.junit.Rule; |
||||
import org.junit.Test; |
||||
import org.springframework.boot.dependency.tools.ManagedDependencies; |
||||
import org.springframework.boot.test.OutputCapture; |
||||
|
||||
import static org.hamcrest.Matchers.containsString; |
||||
import static org.junit.Assert.assertThat; |
||||
|
||||
/** |
||||
* Integration tests for bootRun's resource handling |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
public class BootRunResourceTests { |
||||
|
||||
private static final String BOOT_VERSION = ManagedDependencies.get() |
||||
.find("spring-boot").getVersion(); |
||||
|
||||
private static ProjectConnection project; |
||||
|
||||
@Rule |
||||
public OutputCapture output = new OutputCapture(); |
||||
|
||||
@BeforeClass |
||||
public static void createProject() throws IOException { |
||||
project = new ProjectCreator().createProject("boot-run-resources"); |
||||
} |
||||
|
||||
@Test |
||||
public void resourcesDirectlyFromSource() { |
||||
project.newBuild().forTasks("clean", "bootRun") |
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PaddResources=true") |
||||
.run(); |
||||
|
||||
assertThat(this.output.toString(), containsString("src/main/resources/test.txt")); |
||||
} |
||||
|
||||
@Test |
||||
public void resourcesFromBuildOutput() { |
||||
project.newBuild().forTasks("clean", "bootRun") |
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PaddResources=false") |
||||
.run(); |
||||
assertThat(this.output.toString(), |
||||
containsString("build/resources/main/test.txt")); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
buildscript { |
||||
repositories { |
||||
mavenLocal() |
||||
} |
||||
dependencies { |
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}") |
||||
} |
||||
} |
||||
|
||||
apply plugin: 'java' |
||||
apply plugin: 'spring-boot' |
||||
|
||||
bootRun { |
||||
addResources = Boolean.valueOf(project.addResources) |
||||
} |
||||
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
/* |
||||
* Copyright 2012-2015 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
public class BootRunResourcesApplication { |
||||
|
||||
public static void main(String[] args) { |
||||
ClassLoader classLoader = BootRunResourcesApplication.class.getClassLoader(); |
||||
System.out.println(classLoader.getResource("test.txt")); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue