mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Update samples with Gradle configuration to align with new plugin
This commit is contained in:
parent
d43b1ae3a5
commit
47c0c3c0ef
@ -19,10 +19,7 @@ apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
jar {
|
||||
baseName = 'spring-boot-sample-actuator'
|
||||
}
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'org.springframework.boot'
|
||||
version = springBootVersion
|
||||
@ -37,10 +34,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
configurations {
|
||||
insecure.exclude module: 'spring-boot-starter-security'
|
||||
}
|
||||
|
||||
compile("org.springframework.boot:spring-boot-starter-actuator")
|
||||
compile("org.springframework.boot:spring-boot-starter-jdbc")
|
||||
compile("org.springframework.boot:spring-boot-starter-security")
|
||||
@ -50,18 +43,6 @@ dependencies {
|
||||
compileOnly('org.springframework.boot:spring-boot-configuration-processor')
|
||||
|
||||
testCompile("org.springframework.boot:spring-boot-starter-test")
|
||||
|
||||
insecure configurations.runtime
|
||||
}
|
||||
|
||||
// Slightly odd requirement (package a jar file as an insecure app, excluding Spring Security)
|
||||
// just to demonstrate the "customConfiguration" feature of the Boot gradle plugin.
|
||||
springBoot {
|
||||
customConfiguration = "insecure"
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '1.6'
|
||||
}
|
||||
|
||||
springBoot {
|
||||
|
@ -25,18 +25,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-loader-tools</artifactId>
|
||||
</dependency>
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-tooling-api</artifactId>
|
||||
<version>${gradle.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
@ -96,16 +84,4 @@
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>gradle</id>
|
||||
<url>http://repo.gradle.org/gradle/libs-releases-local</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
||||
|
@ -1,28 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
flatDir {
|
||||
dirs '../..'
|
||||
}
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}"
|
||||
classpath "org.springframework.boot:spring-boot-sample-custom-layout:${project.bootVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
springBoot {
|
||||
layoutFactory = new sample.layout.SampleLayoutFactory('custom')
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'org.springframework.boot:spring-boot-starter'
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
flatDir {
|
||||
dirs '../..'
|
||||
}
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}"
|
||||
classpath "org.springframework.boot:spring-boot-sample-custom-layout:${project.bootVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
dependencies {
|
||||
compile 'org.springframework.boot:spring-boot-starter'
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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 sample.layout;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathExpression;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import org.gradle.tooling.GradleConnector;
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.gradle.tooling.internal.consumer.DefaultGradleConnector;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
public class GradleIT {
|
||||
|
||||
@Test
|
||||
public void sampleDefault() throws Exception {
|
||||
test("default", "sample");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleCustom() throws Exception {
|
||||
test("custom", "custom");
|
||||
}
|
||||
|
||||
private void test(String name, String expected) throws Exception {
|
||||
File projectDirectory = new File("target/gradleit/" + name);
|
||||
File javaDirectory = new File(
|
||||
"target/gradleit/" + name + "/src/main/java/org/test/");
|
||||
projectDirectory.mkdirs();
|
||||
javaDirectory.mkdirs();
|
||||
File script = new File(projectDirectory, "build.gradle");
|
||||
FileCopyUtils.copy(new File("src/it/" + name + "/build.gradle"), script);
|
||||
FileCopyUtils.copy(
|
||||
new File("src/it/" + name
|
||||
+ "/src/main/java/org/test/SampleApplication.java"),
|
||||
new File(javaDirectory, "SampleApplication.java"));
|
||||
GradleConnector gradleConnector = GradleConnector.newConnector();
|
||||
gradleConnector.useGradleVersion("2.9");
|
||||
((DefaultGradleConnector) gradleConnector).embedded(true);
|
||||
ProjectConnection project = gradleConnector.forProjectDirectory(projectDirectory)
|
||||
.connect();
|
||||
project.newBuild().forTasks("clean", "build").setStandardOutput(System.out)
|
||||
.setStandardError(System.err)
|
||||
.withArguments("-PbootVersion=" + getBootVersion()).run();
|
||||
Verify.verify(
|
||||
new File("target/gradleit/" + name + "/build/libs/" + name + ".jar"),
|
||||
expected);
|
||||
}
|
||||
|
||||
public static String getBootVersion() {
|
||||
return evaluateExpression(
|
||||
"/*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']"
|
||||
+ "/text()");
|
||||
}
|
||||
|
||||
private static String evaluateExpression(String expression) {
|
||||
try {
|
||||
XPathFactory xPathFactory = XPathFactory.newInstance();
|
||||
XPath xpath = xPathFactory.newXPath();
|
||||
XPathExpression expr = xpath.compile(expression);
|
||||
String version = expr.evaluate(new InputSource(new FileReader("pom.xml")));
|
||||
return version;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to evaluate expression", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2016 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 sample.layout;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Enumeration;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public final class Verify {
|
||||
|
||||
private Verify() {
|
||||
}
|
||||
|
||||
public static void verify(File file, String entry) throws Exception {
|
||||
ZipFile zipFile = new ZipFile(file);
|
||||
try {
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
if (entries.nextElement().getName().equals(entry)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("No entry " + entry);
|
||||
}
|
||||
finally {
|
||||
zipFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -19,15 +19,10 @@ apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
jar {
|
||||
baseName = 'spring-boot-sample-simple'
|
||||
version = '0.0.0'
|
||||
}
|
||||
|
||||
bootRun {
|
||||
systemProperties = System.properties
|
||||
}
|
||||
version = springBootVersion
|
||||
group = 'org.springframework.boot'
|
||||
|
||||
repositories {
|
||||
// NOTE: You should declare only repositories that you need here
|
||||
@ -41,8 +36,4 @@ repositories {
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter")
|
||||
testCompile("org.springframework.boot:spring-boot-starter-test")
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '1.6'
|
||||
}
|
||||
}
|
@ -19,23 +19,10 @@ apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
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']
|
||||
}
|
||||
version = springBootVersion
|
||||
group = 'org.springframework.boot'
|
||||
|
||||
repositories {
|
||||
// NOTE: You should declare only repositories that you need here
|
||||
@ -49,8 +36,4 @@ repositories {
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter")
|
||||
testCompile("org.springframework.boot:spring-boot-starter-test")
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '1.6'
|
||||
}
|
||||
}
|
@ -37,23 +37,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>lib</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classifier>lib</classifier>
|
||||
<excludes>
|
||||
<exclude>application.yml</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -19,15 +19,10 @@ apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
jar {
|
||||
baseName = 'spring-boot-sample-simple'
|
||||
version = '0.0.0'
|
||||
}
|
||||
|
||||
bootRun {
|
||||
systemProperties = System.properties
|
||||
}
|
||||
version = springBootVersion
|
||||
group = 'org.springframework.boot'
|
||||
|
||||
repositories {
|
||||
// NOTE: You should declare only repositories that you need here
|
||||
@ -40,9 +35,6 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter")
|
||||
compile("org.hibernate:hibernate-validator")
|
||||
testCompile("org.springframework.boot:spring-boot-starter-test")
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '1.6'
|
||||
}
|
||||
|
@ -15,17 +15,12 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse-wtp'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
apply plugin: 'war'
|
||||
|
||||
war {
|
||||
baseName = 'spring-boot-sample-web-static'
|
||||
version = '0.0.0'
|
||||
}
|
||||
version = springBootVersion
|
||||
group = 'org.springframework.boot'
|
||||
|
||||
repositories {
|
||||
// NOTE: You should declare only repositories that you need here
|
||||
@ -36,10 +31,6 @@ repositories {
|
||||
maven { url "http://repo.spring.io/snapshot" }
|
||||
}
|
||||
|
||||
configurations {
|
||||
providedRuntime
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter-web")
|
||||
compile("org.webjars:bootstrap:3.0.3")
|
||||
@ -47,5 +38,3 @@ dependencies {
|
||||
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
|
||||
testCompile("org.springframework.boot:spring-boot-starter-test")
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) { gradleVersion = '1.6' }
|
||||
|
@ -17,20 +17,11 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
springBoot {
|
||||
classifier = 'exec'
|
||||
}
|
||||
|
||||
jar {
|
||||
baseName = 'spring-boot-sample-web-ui'
|
||||
version = '0.0.0'
|
||||
}
|
||||
version = springBootVersion
|
||||
|
||||
repositories {
|
||||
// NOTE: You should declare only repositories that you need here
|
||||
@ -46,5 +37,3 @@ dependencies {
|
||||
compile("org.hibernate:hibernate-validator")
|
||||
testCompile("org.springframework.boot:spring-boot-starter-test")
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) { gradleVersion = '1.6' }
|
||||
|
Loading…
Reference in New Issue
Block a user