Merge branch 'gradle-plugin-rewrite'
This commit is contained in:
@@ -78,7 +78,6 @@
|
||||
<freemarker.version>2.3.25-incubating</freemarker.version>
|
||||
<elasticsearch.version>2.4.4</elasticsearch.version>
|
||||
<glassfish-el.version>3.0.0</glassfish-el.version>
|
||||
<gradle.version>3.4</gradle.version>
|
||||
<groovy.version>2.4.10</groovy.version>
|
||||
<gson.version>2.8.0</gson.version>
|
||||
<h2.version>1.4.194</h2.version>
|
||||
|
||||
@@ -853,6 +853,15 @@
|
||||
</outputDirectory>
|
||||
<excludes>META-INF/**</excludes>
|
||||
</artifactItem>
|
||||
<artifactItem>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-gradle-plugin</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<classifier>docs</classifier>
|
||||
<type>zip</type>
|
||||
<outputDirectory>${project.build.directory}/contents/gradle-plugin</outputDirectory>
|
||||
<excludes>META-INF/**</excludes>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
@@ -164,516 +164,11 @@ Advanced configuration options and examples are available in the
|
||||
|
||||
[[build-tool-plugins-gradle-plugin]]
|
||||
== Spring Boot Gradle plugin
|
||||
The Spring Boot Gradle Plugin provides Spring Boot support in Gradle, allowing you to
|
||||
package executable jar or war archives, run Spring Boot applications and use the
|
||||
dependency management provided by `spring-boot-dependencies`.
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-including-the-gradle-plugin]]
|
||||
=== Including the plugin
|
||||
ifeval::["{spring-boot-repo}" == "release"]
|
||||
To use the Spring Boot Gradle Plugin configure it using the `plugins` block:
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '{spring-boot-version}'
|
||||
}
|
||||
----
|
||||
endif::[]
|
||||
ifeval::["{spring-boot-repo}" != "release"]
|
||||
To use the Spring Boot Gradle Plugin simply include a `buildscript` dependency and apply
|
||||
the `spring-boot` plugin:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url 'http://repo.spring.io/snapshot' }
|
||||
maven { url 'http://repo.spring.io/milestone' }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'org.springframework.boot:spring-boot-gradle-plugin:{spring-boot-version}''
|
||||
}
|
||||
}
|
||||
apply plugin: 'org.springframework.boot'
|
||||
----
|
||||
endif::[]
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-gradle-dependency-management]]
|
||||
=== Gradle dependency management
|
||||
The `spring-boot` plugin automatically applies the
|
||||
{dependency-management-plugin}/[Dependency Management Plugin] and configures it to import
|
||||
the `spring-boot-starter-parent` bom. This provides a similar dependency management
|
||||
experience to the one that is enjoyed by Maven users. For example, it allows you to omit
|
||||
version numbers when declaring dependencies that are managed in the bom. To make use of
|
||||
this functionality, simply declare dependencies in the usual way, but leave the version
|
||||
number empty:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter-web")
|
||||
compile("org.thymeleaf:thymeleaf-spring5")
|
||||
compile("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect")
|
||||
}
|
||||
----
|
||||
|
||||
NOTE: The version of the `spring-boot` gradle plugin that you declare determines the
|
||||
version of the `spring-boot-starter-parent` bom that is imported (this ensures that builds
|
||||
are always repeatable). You should always set the version of the `spring-boot` gradle
|
||||
plugin to the actual Spring Boot version that you wish to use. Details of the versions
|
||||
that are provided can be found in the <<appendix-dependency-versions, appendix>>.
|
||||
|
||||
To learn more about the capabilities of the Dependency Management Plugin, please refer to
|
||||
its {dependency-management-plugin-documentation}[documentation].
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-gradle-packaging]]
|
||||
=== Packaging executable jar and war files
|
||||
Once the `spring-boot` plugin has been applied to your project it will automatically
|
||||
attempt to rewrite archives to make them executable using the
|
||||
<<build-tool-plugins-gradle-repackage-configuration,`bootRepackage` task>>. You
|
||||
should configure your project to build a jar or war (as appropriate) in the usual way.
|
||||
|
||||
The main class that you want to launch can either be specified using a configuration
|
||||
option, or by adding a `Main-Class` attribute to the manifest. If you don't specify a
|
||||
main class the plugin will search for a class with a
|
||||
`public static void main(String[] args)` method.
|
||||
|
||||
TIP: Check <<build-tool-plugins-gradle-repackage-configuration>> for a full list of
|
||||
configuration options.
|
||||
|
||||
To build and run a project artifact, you can type the following:
|
||||
|
||||
[indent=0]
|
||||
----
|
||||
$ gradle build
|
||||
$ java -jar build/libs/mymodule-0.0.1-SNAPSHOT.jar
|
||||
----
|
||||
|
||||
To build a war file that is both executable and deployable into an external container,
|
||||
you need to mark the embedded container dependencies as belonging to the war plugin's
|
||||
`providedRuntime` configuration, e.g.:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
...
|
||||
apply plugin: 'war'
|
||||
|
||||
war {
|
||||
baseName = 'myapp'
|
||||
version = '0.5.0'
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
maven { url "http://repo.spring.io/libs-snapshot" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter-web")
|
||||
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
|
||||
...
|
||||
}
|
||||
----
|
||||
|
||||
TIP: See the "`<<howto-create-a-deployable-war-file>>`" section for more details on
|
||||
how to create a deployable war file.
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-gradle-running-applications]]
|
||||
=== Running a project in-place
|
||||
To run a project in place without building a jar first you can use the "`bootRun`" task:
|
||||
|
||||
[indent=0]
|
||||
----
|
||||
$ gradle bootRun
|
||||
----
|
||||
|
||||
If <<using-spring-boot.adoc#using-boot-devtools,`devtools`>> has been added to your project
|
||||
it will automatically monitor your application for changes. Alternatively, you can also
|
||||
run the application so that your static classpath resources (i.e. in `src/main/resources`
|
||||
by default) are reloadable in the live application, which can be helpful at development
|
||||
time.
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
bootRun {
|
||||
addResources = true
|
||||
}
|
||||
----
|
||||
|
||||
Making static classpath resources reloadable means that `bootRun` does not use the output
|
||||
of the `processResources` task, i.e., when invoked using `bootRun`, your application will
|
||||
use the resources in their unprocessed form.
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-gradle-global-configuration]]
|
||||
=== Spring Boot plugin configuration
|
||||
The gradle plugin automatically extends your build script DSL with a `springBoot` element
|
||||
for global configuration of the Boot plugin. Set the appropriate properties as you would
|
||||
with any other Gradle extension (see below for a list of configuration options):
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
springBoot {
|
||||
backupSource = false
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-gradle-repackage-configuration]]
|
||||
=== Repackage configuration
|
||||
The plugin adds a `bootRepackage` task which you can also configure directly, e.g.:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
bootRepackage {
|
||||
mainClass = 'demo.Application'
|
||||
}
|
||||
----
|
||||
|
||||
The following configuration options are available:
|
||||
|
||||
[cols="2,4"]
|
||||
|===
|
||||
|Name |Description
|
||||
|
||||
|`enabled`
|
||||
|Boolean flag to switch the repackager off (sometimes useful if you
|
||||
want the other Boot features but not this one)
|
||||
|
||||
|`mainClass`
|
||||
|The main class that should be run. If not specified, and you have applied the application
|
||||
plugin, the `mainClassName` project property will be used. If the application plugin has
|
||||
not been applied or no `mainClassName` has been specified, the archive will be searched
|
||||
for a suitable class. "Suitable" means a unique class with a well-formed `main()` method
|
||||
(if more than one is found the build will fail). If you have applied the application
|
||||
plugin, the main class can also be specified via its "run" task (`main` property) and/or
|
||||
its "startScripts" task (`mainClassName` property) as an alternative to using the
|
||||
"springBoot" configuration.
|
||||
|
||||
|`classifier`
|
||||
|A file name segment (before the extension) to add to the archive, so that the original is
|
||||
preserved in its original location. Defaults to `null` in which case the archive is
|
||||
repackaged in place. The default is convenient for many purposes, but if you want to use
|
||||
the original jar as a dependency in another project you must use a classifier to define
|
||||
the executable archive.
|
||||
|
||||
|`withJarTask`
|
||||
|The name or value of the `Jar` task (defaults to all tasks of type `Jar`) which is used
|
||||
to locate the archive to repackage.
|
||||
|
||||
|`customConfiguration`
|
||||
|The name of the custom configuration which is used to populate the nested lib directory
|
||||
(without specifying this you get all compile and runtime dependencies).
|
||||
|
||||
|`executable`
|
||||
|Boolean flag to indicate if jar files are fully executable on Unix like operating
|
||||
systems. Defaults to `false`.
|
||||
|
||||
|`embeddedLaunchScript`
|
||||
|The embedded launch script to prepend to the front of the jar if it is fully executable.
|
||||
If not specified the 'Spring Boot' default script will be used.
|
||||
|
||||
|`embeddedLaunchScriptProperties`
|
||||
|Additional properties that to be expanded in the launch script. The default script
|
||||
supports a `mode` property which can contain the values `auto`, `service` or `run`.
|
||||
|
||||
|`excludeDevtools`
|
||||
|Boolean flag to indicate if the devtools jar should be excluded from the repackaged
|
||||
archives. Defaults to `true`.
|
||||
|===
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-gradle-repackage-custom-configuration]]
|
||||
=== Repackage with custom Gradle configuration
|
||||
Sometimes it may be more appropriate to not package default dependencies resolved from
|
||||
`compile`, `runtime` and `provided` scopes. If the created executable jar file
|
||||
is intended to be run as it is, you need to have all dependencies nested inside it;
|
||||
however, if the plan is to explode a jar file and run the main class manually, you may already
|
||||
have some of the libraries available via `CLASSPATH`. This is a situation where
|
||||
you can repackage your jar with a different set of dependencies.
|
||||
|
||||
Using a custom
|
||||
configuration will automatically disable dependency resolving from
|
||||
`compile`, `runtime` and `provided` scopes. Custom configuration can be either
|
||||
defined globally (inside the `springBoot` section) or per task.
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
task clientJar(type: Jar) {
|
||||
appendix = 'client'
|
||||
from sourceSets.main.output
|
||||
exclude('**/*Something*')
|
||||
}
|
||||
|
||||
task clientBoot(type: BootRepackage, dependsOn: clientJar) {
|
||||
withJarTask = clientJar
|
||||
customConfiguration = "mycustomconfiguration"
|
||||
}
|
||||
----
|
||||
|
||||
In above example, we created a new `clientJar` Jar task to package a customized
|
||||
file set from your compiled sources. Then we created a new `clientBoot`
|
||||
BootRepackage task and instructed it to work with only `clientJar` task and
|
||||
`mycustomconfiguration`.
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
configurations {
|
||||
mycustomconfiguration.exclude group: 'log4j'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
mycustomconfiguration configurations.runtime
|
||||
}
|
||||
----
|
||||
|
||||
The configuration that we are referring to in `BootRepackage` is a normal
|
||||
{gradle-dsl}/org.gradle.api.artifacts.Configuration.html[Gradle
|
||||
configuration]. In the above example we created a new configuration named
|
||||
`mycustomconfiguration` instructing it to derive from a `runtime` and exclude the `log4j`
|
||||
group. If the `clientBoot` task is executed, the repackaged boot jar will have all
|
||||
dependencies from `runtime` but no `log4j` jars.
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-gradle-configuration-options]]
|
||||
==== Configuration options
|
||||
The following configuration options are available:
|
||||
|
||||
[cols="2,4"]
|
||||
|===
|
||||
|Name |Description
|
||||
|
||||
|`mainClass`
|
||||
|The main class that should be run by the executable archive.
|
||||
|
||||
|`providedConfiguration`
|
||||
|The name of the provided configuration (defaults to `providedRuntime`).
|
||||
|
||||
|`backupSource`
|
||||
|If the original source archive should be backed-up before being repackaged (defaults
|
||||
to `true`).
|
||||
|
||||
|`customConfiguration`
|
||||
|The name of the custom configuration.
|
||||
|
||||
|`layout`
|
||||
|The type of archive, corresponding to how the dependencies are laid out inside
|
||||
(defaults to a guess based on the archive type). See
|
||||
<<build-tool-plugins-gradle-configuration-layouts,available layouts for more details>>.
|
||||
|
||||
|`layoutFactory`
|
||||
|A layout factory that can be used if a custom layout is required. Alternative layouts
|
||||
can be provided by 3rd parties. Layout factories are only used when `layout` is not
|
||||
specified.
|
||||
|
||||
|`requiresUnpack`
|
||||
|A list of dependencies (in the form "`groupId:artifactId`" that must be unpacked from
|
||||
fat jars in order to run. Items are still packaged into the fat jar, but they will be
|
||||
automatically unpacked when it runs.
|
||||
|===
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-gradle-configuration-layouts]]
|
||||
==== Available layouts
|
||||
|
||||
The `layout` attribute configures the format of the archive and whether the bootstrap
|
||||
loader should be included or not. The following layouts are available:
|
||||
|
||||
[cols="2,4,1"]
|
||||
|===
|
||||
|Name |Description |Executable
|
||||
|
||||
|`JAR`
|
||||
|Regular executable
|
||||
<<appendix-executable-jar-format.adoc#executable-jar-jar-file-structure,JAR layout>>.
|
||||
|Yes
|
||||
|
||||
|`WAR`
|
||||
|Executable
|
||||
<<appendix-executable-jar-format.adoc#executable-jar-war-file-structure,WAR layout>>.
|
||||
`provided` dependencies are placed in `WEB-INF/lib-provided` to avoid any clash when
|
||||
the `war` is deployed in a servlet container.
|
||||
|Yes
|
||||
|
||||
|`ZIP` (alias to `DIR`)
|
||||
|Similar to `JAR` layout, using
|
||||
<<appendix-executable-jar-format.adoc#executable-jar-property-launcher-features,`PropertiesLauncher`>>.
|
||||
| Yes
|
||||
|
||||
|`MODULE`
|
||||
|Bundle dependencies (excluding those with `provided` scope) and project resources.
|
||||
|No
|
||||
|
||||
|`NONE`
|
||||
|Bundle all dependencies and project resources.
|
||||
|No
|
||||
|===
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-gradle-configuration-custom-repackager]]
|
||||
==== Using a custom layout
|
||||
If you have custom requirements for how to arrange the dependencies and loader classes
|
||||
inside the repackaged jar, you can use a custom layout. Any library which defines one
|
||||
or more `LayoutFactory` implementations can be added to the build script dependencies
|
||||
and then the layout factory becomes available in the `springBoot` configuration.
|
||||
For example:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:{spring-boot-version}")
|
||||
classpath("com.example:custom-layout:1.0.0")
|
||||
}
|
||||
}
|
||||
|
||||
springBoot {
|
||||
layoutFactory = new com.example.CustomLayoutFactory()
|
||||
}
|
||||
----
|
||||
|
||||
NOTE: If there is only one custom `LayoutFactory` on the build classpath and it is
|
||||
listed in `META-INF/spring.factories` then it is unnecessary to explicitly set it in the
|
||||
`springBoot` configuration. Layout factories are only used when no explicit `layout` is
|
||||
specified.
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-understanding-the-gradle-plugin]]
|
||||
=== Understanding how the Gradle plugin works
|
||||
When `spring-boot` is applied to your Gradle project a default task named `bootRepackage`
|
||||
is created automatically. The `bootRepackage` task depends on Gradle `assemble` task, and
|
||||
when executed, it tries to find all jar artifacts whose qualifier is empty (i.e. tests and
|
||||
sources jars are automatically skipped).
|
||||
|
||||
Due to the fact that `bootRepackage` finds 'all' created jar artifacts, the order of
|
||||
Gradle task execution is important. Most projects only create a single jar file, so
|
||||
usually this is not an issue; however, if you are planning to create a more complex
|
||||
project setup, with custom `Jar` and `BootRepackage` tasks, there are few tweaks to
|
||||
consider.
|
||||
|
||||
If you are 'just' creating custom jar files from your project you can simply disable
|
||||
default `jar` and `bootRepackage` tasks:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
jar.enabled = false
|
||||
bootRepackage.enabled = false
|
||||
----
|
||||
|
||||
Another option is to instruct the default `bootRepackage` task to only work with a
|
||||
default `jar` task.
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
bootRepackage.withJarTask = jar
|
||||
----
|
||||
|
||||
If you have a default project setup where the main jar file is created and repackaged,
|
||||
'and' you still want to create additional custom jars, you can combine your custom
|
||||
repackage tasks together and use `dependsOn` so that the `bootJars` task will run after
|
||||
the default `bootRepackage` task is executed:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
task bootJars
|
||||
bootJars.dependsOn = [clientBoot1,clientBoot2,clientBoot3]
|
||||
build.dependsOn(bootJars)
|
||||
----
|
||||
|
||||
All the above tweaks are usually used to avoid situations where an already created boot
|
||||
jar is repackaged again. Repackaging an existing boot jar will not break anything, but
|
||||
you may find that it includes unnecessary dependencies.
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-gradle-publishing-artifacts-to-a-maven-repository]]
|
||||
=== Publishing artifacts to a Maven repository using Gradle
|
||||
If you are <<build-tool-plugins-gradle-dependencies-without-versions, declaring
|
||||
dependencies without versions>> and you want to publish artifacts to a Maven repository
|
||||
you will need to configure the Maven publication with details of Spring Boot's
|
||||
dependency management. This can be achieved by configuring it to publish poms that
|
||||
inherit from `spring-boot-starter-parent` or that import dependency management from
|
||||
`spring-boot-dependencies`. The exact details of this configuration depend on how you're
|
||||
using Gradle and how you're trying to publish the artifacts.
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-gradle-publishing-artifacts-to-a-maven-repository-inherit]]
|
||||
==== Configuring Gradle to produce a pom that inherits dependency management
|
||||
The following is an example of configuring Gradle to generate a pom that inherits
|
||||
from `spring-boot-starter-parent`. Please refer to the
|
||||
{gradle-user-guide}/userguide.html[Gradle User Guide] for further information.
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
uploadArchives {
|
||||
repositories {
|
||||
mavenDeployer {
|
||||
pom {
|
||||
project {
|
||||
parent {
|
||||
groupId "org.springframework.boot"
|
||||
artifactId "spring-boot-starter-parent"
|
||||
version "{spring-boot-version}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-gradle-publishing-artifacts-to-a-maven-repository-import]]
|
||||
==== Configuring Gradle to produce a pom that imports dependency management
|
||||
The following is an example of configuring Gradle to generate a pom that imports
|
||||
the dependency management provided by `spring-boot-dependencies`. Please refer to the
|
||||
http://www.gradle.org/docs/current/userguide/userguide.html[Gradle User Guide] for
|
||||
further information.
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
uploadArchives {
|
||||
repositories {
|
||||
mavenDeployer {
|
||||
pom {
|
||||
project {
|
||||
dependencyManagement {
|
||||
dependencies {
|
||||
dependency {
|
||||
groupId "org.springframework.boot"
|
||||
artifactId "spring-boot-dependencies"
|
||||
version "{spring-boot-version}"
|
||||
type "pom"
|
||||
scope "import"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
----
|
||||
The {spring-boot-gradle-plugin}[Spring Boot Gradle Plugin] provides Spring Boot support
|
||||
in Gradle, allowing you to package executable jar or war archives, run Spring Boot
|
||||
applications and use the dependency management provided by `spring-boot-dependencies`.
|
||||
It requires Gradle 3.4 or later. Please refer to the {spring-boot-gradle-plugin}[plugin's
|
||||
documentation] to learn more.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -827,12 +827,12 @@ Example in Gradle:
|
||||
[source,groovy,indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
configurations {
|
||||
compile.exclude module: "spring-boot-starter-tomcat"
|
||||
compile.exclude module: 'spring-boot-starter-tomcat'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter-web:{spring-boot-version}")
|
||||
compile("org.springframework.boot:spring-boot-starter-jetty:{spring-boot-version}")
|
||||
compile 'org.springframework.boot:spring-boot-starter-web'
|
||||
compile 'org.springframework.boot:spring-boot-starter-jetty'
|
||||
// ...
|
||||
}
|
||||
----
|
||||
@@ -881,12 +881,12 @@ Example in Gradle:
|
||||
[source,groovy,indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
configurations {
|
||||
compile.exclude module: "spring-boot-starter-tomcat"
|
||||
compile.exclude module: 'spring-boot-starter-tomcat'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter-web:{spring-boot-version}")
|
||||
compile("org.springframework.boot:spring-boot-starter-undertow:{spring-boot-version}")
|
||||
compile 'org.springframework.boot:spring-boot-starter-web'
|
||||
compile 'org.springframework.boot:spring-boot-starter-undertow'
|
||||
// ...
|
||||
}
|
||||
----
|
||||
@@ -2355,9 +2355,11 @@ To configure IntelliJ IDEA correctly you can use the `idea` Gradle plugin:
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
buildscript {
|
||||
repositories { jcenter() }
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.springframework.boot:spring-boot-gradle-plugin:{spring-boot-version}"
|
||||
classpath 'org.springframework.boot:spring-boot-gradle-plugin:{spring-boot-version}'
|
||||
classpath 'org.springframework:springloaded:1.2.6.RELEASE'
|
||||
}
|
||||
}
|
||||
@@ -2424,7 +2426,7 @@ And to do the same with Gradle:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
springBoot {
|
||||
springBoot {
|
||||
buildInfo()
|
||||
}
|
||||
----
|
||||
@@ -2502,16 +2504,7 @@ the artifact yourself instead of overriding the property.
|
||||
WARNING: Each Spring Boot release is designed and tested against a specific set of
|
||||
third-party dependencies. Overriding versions may cause compatibility issues.
|
||||
|
||||
To override dependency versions in Gradle, you can specify a version as shown below:
|
||||
|
||||
[source,groovy,indent=0]
|
||||
----
|
||||
ext['slf4j.version'] = '1.7.5'
|
||||
----
|
||||
|
||||
For additional information, please refer to the
|
||||
https://github.com/spring-gradle-plugins/dependency-management-plugin[Gradle Dependency
|
||||
Management Plugin documentation].
|
||||
|
||||
[[howto-create-an-executable-jar-with-maven]]
|
||||
=== Create an executable JAR with Maven
|
||||
@@ -2593,15 +2586,6 @@ To configure a classifier of `exec` in Maven, the following configuration can be
|
||||
</build>
|
||||
----
|
||||
|
||||
And when using Gradle, the following configuration can be used:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
bootRepackage {
|
||||
classifier = 'exec'
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[howto-extract-specific-libraries-when-an-executable-jar-runs]]
|
||||
@@ -2637,15 +2621,6 @@ you would add the following configuration:
|
||||
</build>
|
||||
----
|
||||
|
||||
And to do that same with Gradle:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
springBoot {
|
||||
requiresUnpack = ['org.jruby:jruby-complete']
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[howto-create-a-nonexecutable-jar]]
|
||||
@@ -2689,29 +2664,6 @@ jar must be the main artifact and you can add a classified jar for the library:
|
||||
</build>
|
||||
----
|
||||
|
||||
In Gradle you can create a new JAR archive with standard task DSL features, and then have
|
||||
the `bootRepackage` task depend on that one using its `withJarTask` property:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
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']
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[howto-remote-debug-maven-run]]
|
||||
@@ -2723,34 +2675,6 @@ Check {spring-boot-maven-plugin-site}/examples/run-debug.html[this example] for
|
||||
|
||||
|
||||
|
||||
[[howto-remote-debug-gradle-run]]
|
||||
=== Remote debug a Spring Boot application started with Gradle
|
||||
To attach a remote debugger to a Spring Boot application started with Gradle you can use
|
||||
the `jvmArgs` property of `bootRun` task or `--debug-jvm` command line option.
|
||||
|
||||
`build.gradle`:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
bootRun {
|
||||
jvmArgs "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
Command line:
|
||||
|
||||
[indent=0]
|
||||
----
|
||||
$ gradle bootRun --debug-jvm
|
||||
----
|
||||
|
||||
|
||||
Check {gradle-userguide}/application_plugin.html[Gradle Application Plugin] for more
|
||||
details.
|
||||
|
||||
|
||||
|
||||
[[howto-build-an-executable-archive-with-ant]]
|
||||
=== Build an executable archive from Ant without using spring-boot-antlib
|
||||
To build with Ant you need to grab dependencies, compile and then create a jar or war
|
||||
@@ -2894,10 +2818,9 @@ And if you're using Gradle:
|
||||
}
|
||||
----
|
||||
|
||||
NOTE: If you are using a version of Gradle that supports compile only dependencies (2.12
|
||||
or later), you should continue to use `providedRuntime`. Among other limitations,
|
||||
`compileOnly` dependencies are not on the test classpath so any web-based integration
|
||||
tests will fail.
|
||||
NOTE: `providedRuntime` is prefered to Gradle's `compileOnly` configuration as, among other
|
||||
limitations, `compileOnly` dependencies are not on the test classpath so any web-based
|
||||
integration tests will fail.
|
||||
|
||||
If you're using the <<build-tool-plugins.adoc#build-tool-plugins, Spring Boot build tools>>,
|
||||
marking the embedded servlet container dependency as provided will produce an executable war
|
||||
|
||||
@@ -34,7 +34,8 @@ Phillip Webb; Dave Syer; Josh Long; Stéphane Nicoll; Rob Winch; Andy Wilkinson;
|
||||
:dc-spring-boot-test-autoconfigure: {dc-root}/org/springframework/boot/test/autoconfigure
|
||||
:dependency-management-plugin: https://github.com/spring-gradle-plugins/dependency-management-plugin
|
||||
:dependency-management-plugin-documentation: {dependency-management-plugin}/blob/master/README.md
|
||||
:spring-boot-maven-plugin-site: http://docs.spring.io/spring-boot/docs/{spring-boot-docs-version}/maven-plugin
|
||||
:spring-boot-maven-plugin-site: http://docs.spring.io/spring-boot/docs/{spring-boot-docs-version}/maven-plugin/
|
||||
:spring-boot-gradle-plugin: http://docs.spring.io/spring-boot/docs/{spring-boot-docs-version}/gradle-plugin/
|
||||
:spring-reference: http://docs.spring.io/spring/docs/{spring-docs-version}/spring-framework-reference/htmlsingle
|
||||
:spring-security-reference: http://docs.spring.io/spring-security/site/docs/{spring-security-docs-version}/reference/htmlsingle
|
||||
:spring-security-oauth2-reference: http://projects.spring.io/spring-security-oauth/docs/oauth2.html
|
||||
@@ -50,8 +51,7 @@ Phillip Webb; Dave Syer; Josh Long; Stéphane Nicoll; Rob Winch; Andy Wilkinson;
|
||||
:propdeps-plugin: https://github.com/spring-projects/gradle-plugins/tree/master/propdeps-plugin
|
||||
:ant-manual: http://ant.apache.org/manual
|
||||
:code-examples: ../java/org/springframework/boot
|
||||
:gradle-user-guide: https://docs.gradle.org/2.14.1/userguide
|
||||
:gradle-dsl: https://docs.gradle.org/2.14.1/dsl
|
||||
:gradle-user-guide: https://docs.gradle.org/3.4.1/userguide
|
||||
// ======================================================================================
|
||||
|
||||
include::documentation-overview.adoc[]
|
||||
|
||||
@@ -41,8 +41,8 @@ feel that's necessary.
|
||||
The curated list contains all the spring modules that you can use with Spring Boot as
|
||||
well as a refined list of third party libraries. The list is available as a standard
|
||||
<<using-boot-maven-without-a-parent,Bills of Materials (`spring-boot-dependencies`)>>
|
||||
and additional dedicated support for <<using-boot-maven-parent-pom,Maven>> and
|
||||
<<build-tool-plugins-gradle-dependency-management,Gradle>> are available as well.
|
||||
that can be used with both <<using-boot-maven-parent-pom,Maven>> and
|
||||
{spring-boot-gradle-plugin}[Gradle].
|
||||
|
||||
WARNING: Each release of Spring Boot is associated with a base version of the Spring
|
||||
Framework so we **highly** recommend you to not specify its version on your own.
|
||||
@@ -194,70 +194,8 @@ the parent.
|
||||
|
||||
[[using-boot-gradle]]
|
||||
=== Gradle
|
||||
Gradle users can directly import '`starters`' in their `dependencies` section. Unlike
|
||||
Maven, there is no "`super parent`" to import to share some configuration.
|
||||
|
||||
[source,groovy,indent=0,subs="attributes"]
|
||||
----
|
||||
repositories {
|
||||
ifeval::["{spring-boot-repo}" != "release"]
|
||||
maven { url "http://repo.spring.io/snapshot" }
|
||||
maven { url "http://repo.spring.io/milestone" }
|
||||
endif::[]
|
||||
ifeval::["{spring-boot-repo}" == "release"]
|
||||
jcenter()
|
||||
endif::[]
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter-web:{spring-boot-version}")
|
||||
}
|
||||
----
|
||||
|
||||
The <<build-tool-plugins.adoc#build-tool-plugins-gradle-plugin,
|
||||
`spring-boot-gradle-plugin`>> is also available and provides tasks to create executable
|
||||
jars and run projects from source. It also provides
|
||||
<<build-tool-plugins-gradle-dependency-management, dependency management>> that, among
|
||||
other capabilities, allows you to omit the version number for any dependencies that are
|
||||
managed by Spring Boot:
|
||||
|
||||
[source,groovy,indent=0,subs="attributes"]
|
||||
----
|
||||
ifeval::["{spring-boot-repo}" == "release"]
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '{spring-boot-version}'
|
||||
id 'java'
|
||||
}
|
||||
endif::[]
|
||||
ifeval::["{spring-boot-repo}" != "release"]
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven { url 'http://repo.spring.io/snapshot' }
|
||||
maven { url 'http://repo.spring.io/milestone' }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'org.springframework.boot:spring-boot-gradle-plugin:{spring-boot-version}'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
endif::[]
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
ifeval::["{spring-boot-repo}" != "release"]
|
||||
maven { url 'http://repo.spring.io/snapshot' }
|
||||
maven { url 'http://repo.spring.io/milestone' }
|
||||
endif::[]
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter-web")
|
||||
testCompile("org.springframework.boot:spring-boot-starter-test")
|
||||
}
|
||||
----
|
||||
To learn about using Spring Boot with Gradle, please refer to the
|
||||
{spring-boot-gradle-plugin}[documentation for Spring Boot's Gradle plugin].
|
||||
|
||||
|
||||
|
||||
@@ -704,8 +642,8 @@ You might also want to use the useful operating system environment variable:
|
||||
[[using-boot-running-with-the-gradle-plugin]]
|
||||
=== Using the Gradle plugin
|
||||
The Spring Boot Gradle plugin also includes a `bootRun` task which can be used to run
|
||||
your application in an exploded form. The `bootRun` task is added whenever you import
|
||||
the `spring-boot-gradle-plugin`:
|
||||
your application in an exploded form. The `bootRun` task is added whenever you apply the
|
||||
the `org.springframework.boot` and `java` plugins:
|
||||
|
||||
[indent=0,subs="attributes"]
|
||||
----
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
<modules>
|
||||
<module>spring-boot-devtools-tests</module>
|
||||
<module>spring-boot-integration-tests-embedded-servlet-container</module>
|
||||
<module>spring-boot-gradle-tests</module>
|
||||
<module>spring-boot-launch-script-tests</module>
|
||||
<module>spring-boot-security-tests</module>
|
||||
</modules>
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-integration-tests</artifactId>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-boot-gradle-tests</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Spring Boot Gradle Integration Tests</name>
|
||||
<description>Spring Boot Gradle Integration Tests</description>
|
||||
<url>http://projects.spring.io/spring-boot/</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>http://www.spring.io</url>
|
||||
</organization>
|
||||
<properties>
|
||||
<main.basedir>${basedir}/../..</main.basedir>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-tooling-api</artifactId>
|
||||
<version>${gradle.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-model-builder</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-effective-pom</id>
|
||||
<phase>generate-test-resources</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>effective-pom</type>
|
||||
<overWrite>true</overWrite>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
<destFileName>dependencies-pom.xml</destFileName>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</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,66 +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 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.test.rule.OutputCapture;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for bootRun's resource handling
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class BootRunResourceTests {
|
||||
|
||||
private static final String BOOT_VERSION = Versions.getBootVersion();
|
||||
|
||||
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")
|
||||
.setStandardOutput(System.out).run();
|
||||
|
||||
assertThat(this.output.toString()).contains("src/main/resources/test.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resourcesFromBuildOutput() {
|
||||
project.newBuild().forTasks("clean", "bootRun")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PaddResources=false")
|
||||
.setStandardOutput(System.out).run();
|
||||
assertThat(this.output.toString()).contains("build/resources/main/test.txt");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,62 +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 org.springframework.boot.gradle;
|
||||
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for using the Gradle plugin's support for installing artifacts
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class ClassifierTests {
|
||||
|
||||
private ProjectConnection project;
|
||||
|
||||
private static final String BOOT_VERSION = Versions.getBootVersion();
|
||||
|
||||
@Test
|
||||
public void classifierInBootTask() throws Exception {
|
||||
this.project = new ProjectCreator().createProject("classifier");
|
||||
this.project.newBuild().forTasks("build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
checkFilesExist("classifier");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void classifierInBootExtension() throws Exception {
|
||||
this.project = new ProjectCreator().createProject("classifier-extension");
|
||||
this.project.newBuild().forTasks("build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace", "--info")
|
||||
.run();
|
||||
}
|
||||
|
||||
private void checkFilesExist(String name) throws Exception {
|
||||
JarFile jar = new JarFile("target/" + name + "/build/libs/" + name + ".jar");
|
||||
assertThat(jar.getManifest()).isNotNull();
|
||||
jar.close();
|
||||
jar = new JarFile("target/" + name + "/build/libs/" + name + "-exec.jar");
|
||||
assertThat(jar.getManifest()).isNotNull();
|
||||
jar.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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.File;
|
||||
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
/**
|
||||
* Tests for using the Gradle plugin's support for flat directory repos
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class FlatdirTests {
|
||||
|
||||
private ProjectConnection project;
|
||||
|
||||
private File libs = new File("target/flatdir/lib");
|
||||
|
||||
private static final String BOOT_VERSION = Versions.getBootVersion();
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
if (this.libs.exists()) {
|
||||
FileSystemUtils.deleteRecursively(this.libs);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flatdir() throws Exception {
|
||||
this.project = new ProjectCreator().createProject("flatdir");
|
||||
if (!this.libs.exists()) {
|
||||
this.libs.mkdirs();
|
||||
}
|
||||
FileCopyUtils.copy(new File("src/test/resources/foo.jar"),
|
||||
new File(this.libs, "foo-1.0.0.jar"));
|
||||
this.project.newBuild().forTasks("build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,182 +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 org.springframework.boot.gradle;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for creating a fully executable jar with Gradle.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class FullyExecutableJarTests {
|
||||
|
||||
private static final String BOOT_VERSION = Versions.getBootVersion();
|
||||
|
||||
private static ProjectConnection project;
|
||||
|
||||
@BeforeClass
|
||||
public static void createProject() throws IOException {
|
||||
project = new ProjectCreator().createProject("executable-jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarIsNotExecutableByDefault() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION).run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(isFullyExecutable(executableJar)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void madeExecutableViaExtension() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build").withArguments(
|
||||
"-PbootVersion=" + BOOT_VERSION, "-PextensionExecutable=true").run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(isFullyExecutable(executableJar)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void madeExecutableViaTask() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PtaskExecutable=true")
|
||||
.run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(isFullyExecutable(executableJar)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskTakesPrecedenceForMakingJarExecutable() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION,
|
||||
"-PextensionExecutable=false", "-PtaskExecutable=true")
|
||||
.run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(isFullyExecutable(executableJar)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptPropertiesFromTask() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PtaskProperties=true")
|
||||
.run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(isFullyExecutable(executableJar)).isTrue();
|
||||
assertThat(containsLine("# Provides:.*__task__", executableJar)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptPropertiesFromExtension() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build").withArguments(
|
||||
"-PbootVersion=" + BOOT_VERSION, "-PextensionProperties=true").run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(isFullyExecutable(executableJar)).isTrue();
|
||||
assertThat(containsLine("# Provides:.*__extension__", executableJar)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskTakesPrecedenceForScriptProperties() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION,
|
||||
"-PextensionProperties=true", "-PtaskProperties=true")
|
||||
.run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(isFullyExecutable(executableJar)).isTrue();
|
||||
assertThat(containsLine("# Provides:.*__task__", executableJar)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customScriptFromTask() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PtaskScript=true")
|
||||
.run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(containsLine("Custom task script", executableJar)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customScriptFromExtension() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PextensionScript=true")
|
||||
.run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(containsLine("Custom extension script", executableJar)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskTakesPrecedenceForCustomScript() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PextensionScript=true",
|
||||
"-PtaskScript=true")
|
||||
.run();
|
||||
File buildLibs = new File("target/executable-jar/build/libs");
|
||||
File executableJar = new File(buildLibs, "executable-jar.jar");
|
||||
assertThat(containsLine("Custom task script", executableJar)).isTrue();
|
||||
}
|
||||
|
||||
private boolean isFullyExecutable(File file) throws IOException {
|
||||
return containsLine("#!/bin/bash", file);
|
||||
}
|
||||
|
||||
private boolean containsLine(String toMatch, File file) throws IOException {
|
||||
Pattern pattern = Pattern.compile(toMatch);
|
||||
for (String line : readLines(file)) {
|
||||
if (pattern.matcher(line).matches()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<String> readLines(File file) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
List<String> lines = new ArrayList<>();
|
||||
try {
|
||||
String line = reader.readLine();
|
||||
while (line != null && lines.size() < 50) {
|
||||
lines.add(line);
|
||||
line = reader.readLine();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +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 org.springframework.boot.gradle;
|
||||
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for using the Gradle plugin's support for installing artifacts
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class InstallTests {
|
||||
|
||||
private ProjectConnection project;
|
||||
|
||||
private static final String BOOT_VERSION = Versions.getBootVersion();
|
||||
|
||||
@Test
|
||||
public void cleanInstall() throws Exception {
|
||||
this.project = new ProjectCreator().createProject("installer");
|
||||
this.project.newBuild().forTasks("install")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cleanInstallDist() throws Exception {
|
||||
this.project = new ProjectCreator().createProject("install-app");
|
||||
this.project.newBuild().forTasks("installDist")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +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 org.springframework.boot.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.gradle.tooling.BuildException;
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for configuring a project's main class.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class MainClassTests {
|
||||
|
||||
private static final String BOOT_VERSION = Versions.getBootVersion();
|
||||
|
||||
private static ProjectConnection project;
|
||||
|
||||
@BeforeClass
|
||||
public static void createProject() throws IOException {
|
||||
project = new ProjectCreator().createProject("main-class");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mainFromBootRun() {
|
||||
project.newBuild().forTasks("build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-PbootRunMain=true")
|
||||
.run();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonJavaExecRunTaskIsIgnored() {
|
||||
try {
|
||||
project.newBuild().forTasks("build").withArguments(
|
||||
"-PbootVersion=" + BOOT_VERSION, "-PnonJavaExecRun=true").run();
|
||||
}
|
||||
catch (BuildException ex) {
|
||||
Throwable rootCause = getRootCause(ex);
|
||||
assertThat(rootCause.getMessage()).isEqualTo("Unable to find main class");
|
||||
}
|
||||
}
|
||||
|
||||
private Throwable getRootCause(Throwable ex) {
|
||||
Throwable candidate = ex;
|
||||
while (candidate.getCause() != null) {
|
||||
candidate = candidate.getCause();
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,84 +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 org.springframework.boot.gradle;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.assertj.core.description.TextDescription;
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.not;
|
||||
|
||||
/**
|
||||
* Integration tests for Gradle repackaging with two different versions of the same
|
||||
* dependency.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class MixedVersionRepackagingTests {
|
||||
|
||||
private static final String BOOT_VERSION = Versions.getBootVersion();
|
||||
|
||||
private static ProjectConnection project;
|
||||
|
||||
@BeforeClass
|
||||
public static void createProject() throws IOException {
|
||||
project = new ProjectCreator().createProject("mixed-version-repackaging");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleVersionIsIncludedInJar() throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true",
|
||||
"-PexcludeDevtools=false")
|
||||
.run();
|
||||
File buildLibs = new File("target/mixed-version-repackaging/build/libs");
|
||||
File repackageFile = new File(buildLibs, "mixed-version-repackaging.jar");
|
||||
assertThat(repackageFile.exists()).isTrue();
|
||||
assertThat(new JarFile(repackageFile))
|
||||
.has(entryNamed("BOOT-INF/lib/guava-18.0.jar"));
|
||||
assertThat(new JarFile(repackageFile))
|
||||
.has(not(entryNamed("BOOT-INF/lib/guava-16.0.jar")));
|
||||
}
|
||||
|
||||
private Condition<JarFile> entryNamed(String name) {
|
||||
return new JarFileEntryCondition(name);
|
||||
}
|
||||
|
||||
private final class JarFileEntryCondition extends Condition<JarFile> {
|
||||
|
||||
private final String entryName;
|
||||
|
||||
private JarFileEntryCondition(String entryName) {
|
||||
super(new TextDescription("entry named '%s'", entryName));
|
||||
this.entryName = entryName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(JarFile jarFile) {
|
||||
return jarFile.getEntry(this.entryName) != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,78 +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 org.springframework.boot.gradle;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for Gradle repackaging with a multi-project build.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class MultiProjectRepackagingTests {
|
||||
|
||||
private static final String BOOT_VERSION = Versions.getBootVersion();
|
||||
|
||||
@Test
|
||||
public void repackageWithTransitiveFileDependency() throws Exception {
|
||||
ProjectConnection project = new ProjectCreator()
|
||||
.createProject("multi-project-transitive-file-dependency");
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION).run();
|
||||
File buildLibs = new File(
|
||||
"target/multi-project-transitive-file-dependency/main/build/libs");
|
||||
JarFile jarFile = new JarFile(new File(buildLibs, "main.jar"));
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/commons-logging-1.1.3.jar"))
|
||||
.isNotNull();
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/foo.jar")).isNotNull();
|
||||
jarFile.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackageWithCommonFileDependency() throws Exception {
|
||||
ProjectConnection project = new ProjectCreator()
|
||||
.createProject("multi-project-common-file-dependency");
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION).run();
|
||||
File buildLibs = new File(
|
||||
"target/multi-project-common-file-dependency/build/libs");
|
||||
JarFile jarFile = new JarFile(
|
||||
new File(buildLibs, "multi-project-common-file-dependency.jar"));
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/foo.jar")).isNotNull();
|
||||
jarFile.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackageWithRuntimeProjectDependency() throws Exception {
|
||||
ProjectConnection project = new ProjectCreator()
|
||||
.createProject("multi-project-runtime-project-dependency");
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION).run();
|
||||
File buildLibs = new File(
|
||||
"target/multi-project-runtime-project-dependency/projectA/build/libs");
|
||||
JarFile jarFile = new JarFile(new File(buildLibs, "projectA.jar"));
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/projectB.jar")).isNotNull();
|
||||
jarFile.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,66 +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 org.springframework.boot.gradle;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.gradle.tooling.GradleConnector;
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.gradle.tooling.internal.consumer.DefaultGradleConnector;
|
||||
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
/**
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ProjectCreator {
|
||||
|
||||
private String gradleVersion;
|
||||
|
||||
public ProjectCreator() {
|
||||
this("3.4");
|
||||
}
|
||||
|
||||
public ProjectCreator(String gradleVersion) {
|
||||
this.gradleVersion = gradleVersion;
|
||||
}
|
||||
|
||||
public ProjectConnection createProject(String name) throws IOException {
|
||||
File projectDirectory = new File("target/" + name);
|
||||
projectDirectory.mkdirs();
|
||||
|
||||
File gradleScript = new File(projectDirectory, "build.gradle");
|
||||
|
||||
if (new File("src/test/resources", name).isDirectory()) {
|
||||
FileSystemUtils.copyRecursively(new File("src/test/resources", name),
|
||||
projectDirectory);
|
||||
}
|
||||
else {
|
||||
FileCopyUtils.copy(new File("src/test/resources/" + name + ".gradle"),
|
||||
gradleScript);
|
||||
}
|
||||
|
||||
GradleConnector gradleConnector = GradleConnector.newConnector();
|
||||
gradleConnector.useGradleVersion(this.gradleVersion);
|
||||
|
||||
((DefaultGradleConnector) gradleConnector).embedded(true);
|
||||
return gradleConnector.forProjectDirectory(projectDirectory).connect();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,210 +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 org.springframework.boot.gradle;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.gradle.tooling.BuildLauncher;
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for gradle repackaging.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class RepackagingTests {
|
||||
|
||||
private static final String BOOT_VERSION = Versions.getBootVersion();
|
||||
|
||||
private static ProjectConnection project;
|
||||
|
||||
@BeforeClass
|
||||
public static void createProject() throws IOException {
|
||||
project = new ProjectCreator().createProject("repackage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackagingEnabled() throws IOException {
|
||||
createBuildForTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
File repackageFile = new File(buildLibs, "repackage.jar");
|
||||
assertThat(repackageFile.exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackagingDisabled() {
|
||||
createBuildForTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false")
|
||||
.run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
assertThat(new File(buildLibs, "repackage.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackagingDisabledWithCustomRepackagedJar() {
|
||||
createBuildForTasks("clean", "build", "customRepackagedJar")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false")
|
||||
.run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
assertThat(new File(buildLibs, "repackage.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(new File(buildLibs, "custom.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "custom.jar.original").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackagingDisabledWithCustomRepackagedJarUsingStringJarTaskReference() {
|
||||
project.newBuild()
|
||||
.forTasks("clean", "build", "customRepackagedJarWithStringReference")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=false")
|
||||
.run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
assertThat(new File(buildLibs, "repackage.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isFalse();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(new File(buildLibs, "custom.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "custom.jar.original").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackagingEnabledWithCustomRepackagedJar() {
|
||||
createBuildForTasks("clean", "build", "customRepackagedJar")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
assertThat(new File(buildLibs, "repackage.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(new File(buildLibs, "custom.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "custom.jar.original").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackagingEnableWithCustomRepackagedJarUsingStringJarTaskReference() {
|
||||
project.newBuild()
|
||||
.forTasks("clean", "build", "customRepackagedJarWithStringReference")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
assertThat(new File(buildLibs, "repackage.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(new File(buildLibs, "custom.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "custom.jar.original").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repackageWithFileDependency() throws Exception {
|
||||
FileCopyUtils.copy(new File("src/test/resources/foo.jar"),
|
||||
new File("target/repackage/foo.jar"));
|
||||
createBuildForTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
JarFile jarFile = new JarFile(new File(buildLibs, "repackage.jar"));
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/foo.jar")).isNotNull();
|
||||
jarFile.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void devtoolsIsExcludedByDefault() throws IOException {
|
||||
createBuildForTasks("clean", "bootRepackage")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
File repackageFile = new File(buildLibs, "repackage.jar");
|
||||
assertThat(repackageFile.exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(isDevToolsJarIncluded(repackageFile)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void devtoolsCanBeIncludedUsingTheExtension() throws IOException {
|
||||
createBuildForTasks("clean", "bootRepackage")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true",
|
||||
"-PexcludeDevtoolsOnExtension=false")
|
||||
.run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
File repackageFile = new File(buildLibs, "repackage.jar");
|
||||
assertThat(repackageFile.exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(isDevToolsJarIncluded(repackageFile)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void devtoolsCanBeIncludedUsingBootRepackage() throws IOException {
|
||||
createBuildForTasks("clean", "bootRepackage")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true",
|
||||
"-PexcludeDevtoolsOnBootRepackage=false")
|
||||
.run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
File repackageFile = new File(buildLibs, "repackage.jar");
|
||||
assertThat(repackageFile.exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage.jar.original").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "repackage-sources.jar.original").exists())
|
||||
.isFalse();
|
||||
assertThat(isDevToolsJarIncluded(repackageFile)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customRepackagingTaskWithOwnMainClassNameAnNoGlobalMainClassName() {
|
||||
createBuildForTasks("clean", "customRepackagedJarWithOwnMainClass")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true",
|
||||
"-PnoMainClass=true")
|
||||
.run();
|
||||
File buildLibs = new File("target/repackage/build/libs");
|
||||
assertThat(new File(buildLibs, "custom.jar").exists()).isTrue();
|
||||
assertThat(new File(buildLibs, "custom.jar.original").exists()).isTrue();
|
||||
}
|
||||
|
||||
private BuildLauncher createBuildForTasks(String... taskNames) {
|
||||
return project.newBuild().setStandardError(System.err)
|
||||
.setStandardOutput(System.out).forTasks(taskNames);
|
||||
}
|
||||
|
||||
private boolean isDevToolsJarIncluded(File repackageFile) throws IOException {
|
||||
JarFile jarFile = new JarFile(repackageFile);
|
||||
try {
|
||||
String name = "BOOT-INF/lib/spring-boot-devtools-" + BOOT_VERSION + ".jar";
|
||||
return jarFile.getEntry(name) != null;
|
||||
}
|
||||
finally {
|
||||
jarFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,95 +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 org.springframework.boot.gradle;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for the Gradle plugin's Spring Loaded support
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class SpringLoadedTests {
|
||||
|
||||
private static final String BOOT_VERSION = Versions.getBootVersion();
|
||||
|
||||
private static final String SPRING_LOADED_VERSION = Versions.getSpringLoadedVersion();
|
||||
|
||||
@Test
|
||||
public void defaultJvmArgsArePreservedWhenLoadedAgentIsConfigured()
|
||||
throws IOException {
|
||||
ProjectConnection project = new ProjectCreator()
|
||||
.createProject("spring-loaded-jvm-args");
|
||||
project.newBuild().forTasks("bootRun")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION,
|
||||
"-PspringLoadedVersion=" + SPRING_LOADED_VERSION, "--stacktrace")
|
||||
.run();
|
||||
|
||||
List<String> output = getOutput();
|
||||
assertOutputContains("-DSOME_ARG=someValue", output);
|
||||
assertOutputContains("-Xverify:none", output);
|
||||
assertOutputMatches("-javaagent:.*springloaded-" + SPRING_LOADED_VERSION + ".jar",
|
||||
output);
|
||||
}
|
||||
|
||||
private List<String> getOutput() throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(
|
||||
new File("target/spring-loaded-jvm-args/build/output.txt")));
|
||||
try {
|
||||
List<String> lines = new ArrayList<>();
|
||||
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
lines.add(line);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void assertOutputContains(String requiredOutput, List<String> actualOutput) {
|
||||
for (String line : actualOutput) {
|
||||
if (line.equals(requiredOutput)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
fail("Required output '" + requiredOutput + "' not found in " + actualOutput);
|
||||
}
|
||||
|
||||
private void assertOutputMatches(String requiredPattern, List<String> actualOutput) {
|
||||
for (String line : actualOutput) {
|
||||
if (line.matches(requiredPattern)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
fail("Required pattern '" + requiredPattern + "' not matched in " + actualOutput);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,66 +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 org.springframework.boot.gradle;
|
||||
|
||||
import java.io.FileReader;
|
||||
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathExpression;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
/**
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public final class Versions {
|
||||
|
||||
private Versions() {
|
||||
}
|
||||
|
||||
public static String getBootVersion() {
|
||||
return evaluateExpression(
|
||||
"/*[local-name()='project']/*[local-name()='version']" + "/text()");
|
||||
}
|
||||
|
||||
public static String getSpringLoadedVersion() {
|
||||
return evaluateExpression(
|
||||
"/*[local-name()='project']/*[local-name()='properties']"
|
||||
+ "/*[local-name()='spring-loaded.version']/text()");
|
||||
}
|
||||
|
||||
public static String getSpringVersion() {
|
||||
return evaluateExpression(
|
||||
"/*[local-name()='project']/*[local-name()='properties']"
|
||||
+ "/*[local-name()='spring.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("target/dependencies-pom.xml")));
|
||||
return version;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to evaluate expression", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,181 +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 org.springframework.boot.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for war packaging with Gradle to ensure that only the Servlet container and its
|
||||
* dependencies are packaged in WEB-INF/lib-provided
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class WarPackagingTests {
|
||||
|
||||
private static final String WEB_INF_LIB_PROVIDED_PREFIX = "WEB-INF/lib-provided/";
|
||||
|
||||
private static final String WEB_INF_LIB_PREFIX = "WEB-INF/lib/";
|
||||
|
||||
private static final Set<String> TOMCAT_EXPECTED_IN_WEB_INF_LIB_PROVIDED = new HashSet<>(
|
||||
Arrays.asList("spring-boot-starter-tomcat-", "tomcat-embed-core-",
|
||||
"tomcat-embed-el-", "tomcat-embed-websocket-"));
|
||||
|
||||
private static final Set<String> JETTY_EXPECTED_IN_WEB_INF_LIB_PROVIDED = new HashSet<>(
|
||||
Arrays.asList("spring-boot-starter-jetty-", "jetty-continuation",
|
||||
"jetty-util-", "javax.servlet-", "jetty-client", "jetty-io-",
|
||||
"jetty-http-", "jetty-server-", "jetty-security-", "jetty-servlet-",
|
||||
"jetty-servlets", "jetty-webapp-", "websocket-api",
|
||||
"javax.annotation-api", "jetty-plus", "javax-websocket-server-impl-",
|
||||
"apache-el", "asm-", "javax.websocket-api-", "asm-tree-",
|
||||
"asm-commons-", "websocket-common-", "jetty-annotations-",
|
||||
"javax-websocket-client-impl-", "websocket-client-",
|
||||
"websocket-server-", "jetty-xml-", "websocket-servlet-"));
|
||||
|
||||
private static final String BOOT_VERSION = Versions.getBootVersion();
|
||||
|
||||
private static ProjectConnection project;
|
||||
|
||||
@BeforeClass
|
||||
public static void createProject() throws IOException {
|
||||
project = new ProjectCreator().createProject("war-packaging");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyTomcatIsPackagedInWebInfLibProvided() throws IOException {
|
||||
checkWebInfEntriesForWebServer("tomcat",
|
||||
TOMCAT_EXPECTED_IN_WEB_INF_LIB_PROVIDED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyJettyIsPackagedInWebInfLibProvided() throws IOException {
|
||||
checkWebInfEntriesForWebServer("jetty",
|
||||
JETTY_EXPECTED_IN_WEB_INF_LIB_PROVIDED);
|
||||
}
|
||||
|
||||
private void checkWebInfEntriesForWebServer(String webServer,
|
||||
Set<String> expectedLibProvidedEntries) throws IOException {
|
||||
project.newBuild().forTasks("clean", "build")
|
||||
.withArguments("-PbootVersion=" + BOOT_VERSION,
|
||||
"-PservletContainer=" + webServer)
|
||||
.run();
|
||||
|
||||
JarFile war = new JarFile("target/war-packaging/build/libs/war-packaging.war");
|
||||
|
||||
checkWebInfLibProvidedEntries(war, expectedLibProvidedEntries);
|
||||
|
||||
checkWebInfLibEntries(war, expectedLibProvidedEntries);
|
||||
|
||||
try {
|
||||
war.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
private void checkWebInfLibProvidedEntries(JarFile war, Set<String> expectedEntries)
|
||||
throws IOException {
|
||||
Set<String> entries = getWebInfLibProvidedEntries(war);
|
||||
assertThat(entries).hasSameSizeAs(expectedEntries);
|
||||
List<String> unexpectedLibProvidedEntries = new ArrayList<>();
|
||||
for (String entry : entries) {
|
||||
if (!isExpectedInWebInfLibProvided(entry, expectedEntries)) {
|
||||
unexpectedLibProvidedEntries.add(entry);
|
||||
}
|
||||
}
|
||||
assertThat(unexpectedLibProvidedEntries.isEmpty());
|
||||
}
|
||||
|
||||
private void checkWebInfLibEntries(JarFile war, Set<String> entriesOnlyInLibProvided)
|
||||
throws IOException {
|
||||
Set<String> entries = getWebInfLibEntries(war);
|
||||
List<String> unexpectedLibEntries = new ArrayList<>();
|
||||
for (String entry : entries) {
|
||||
if (!isExpectedInWebInfLib(entry, entriesOnlyInLibProvided)) {
|
||||
unexpectedLibEntries.add(entry);
|
||||
}
|
||||
}
|
||||
assertThat(unexpectedLibEntries.isEmpty());
|
||||
}
|
||||
|
||||
private Set<String> getWebInfLibProvidedEntries(JarFile war) throws IOException {
|
||||
Set<String> webInfLibProvidedEntries = new HashSet<>();
|
||||
Enumeration<JarEntry> entries = war.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
String name = entries.nextElement().getName();
|
||||
if (isWebInfLibProvidedEntry(name)) {
|
||||
webInfLibProvidedEntries.add(name);
|
||||
}
|
||||
}
|
||||
return webInfLibProvidedEntries;
|
||||
}
|
||||
|
||||
private Set<String> getWebInfLibEntries(JarFile war) throws IOException {
|
||||
Set<String> webInfLibEntries = new HashSet<>();
|
||||
Enumeration<JarEntry> entries = war.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
String name = entries.nextElement().getName();
|
||||
if (isWebInfLibEntry(name)) {
|
||||
webInfLibEntries.add(name);
|
||||
}
|
||||
}
|
||||
return webInfLibEntries;
|
||||
}
|
||||
|
||||
private boolean isWebInfLibProvidedEntry(String name) {
|
||||
return name.startsWith(WEB_INF_LIB_PROVIDED_PREFIX)
|
||||
&& !name.equals(WEB_INF_LIB_PROVIDED_PREFIX);
|
||||
}
|
||||
|
||||
private boolean isWebInfLibEntry(String name) {
|
||||
return name.startsWith(WEB_INF_LIB_PREFIX) && !name.equals(WEB_INF_LIB_PREFIX);
|
||||
}
|
||||
|
||||
private boolean isExpectedInWebInfLibProvided(String name,
|
||||
Set<String> expectedEntries) {
|
||||
for (String expected : expectedEntries) {
|
||||
if (name.startsWith(WEB_INF_LIB_PROVIDED_PREFIX + expected)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isExpectedInWebInfLib(String name, Set<String> unexpectedEntries) {
|
||||
for (String unexpected : unexpectedEntries) {
|
||||
if (name.startsWith(WEB_INF_LIB_PREFIX + unexpected)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,114 +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 org.springframework.boot.starter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.gradle.tooling.BuildException;
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import org.springframework.boot.gradle.ProjectCreator;
|
||||
import org.springframework.boot.gradle.Versions;
|
||||
|
||||
/**
|
||||
* Tests for the various starter projects to check that they don't pull in unwanted
|
||||
* transitive dependencies when used with Gradle
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class StarterDependenciesIntegrationTests {
|
||||
|
||||
private static final String STARTER_NAME_PREFIX = "spring-boot-starter";
|
||||
|
||||
private static final List<String> EXCLUDED_STARTERS = Arrays
|
||||
.asList("spring-boot-starter-parent");
|
||||
|
||||
private static ProjectConnection project;
|
||||
|
||||
private static String bootVersion;
|
||||
|
||||
private static String springVersion;
|
||||
|
||||
private final String[] buildArguments;
|
||||
|
||||
@Parameters
|
||||
public static List<String[]> getStarters() {
|
||||
List<String[]> starters = new ArrayList<>();
|
||||
for (File file : new File("../../spring-boot-starters").listFiles()) {
|
||||
if (file.isDirectory() && new File(file, "pom.xml").exists()) {
|
||||
String name = file.getName();
|
||||
if (name.startsWith(STARTER_NAME_PREFIX)
|
||||
&& !EXCLUDED_STARTERS.contains(file.getName())) {
|
||||
starters.add(new String[] { file.getName() });
|
||||
}
|
||||
}
|
||||
}
|
||||
return starters;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void createProject() throws IOException {
|
||||
project = new ProjectCreator().createProject("starter-dependencies");
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void determineVersions() throws Exception {
|
||||
springVersion = Versions.getSpringVersion();
|
||||
bootVersion = Versions.getBootVersion();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void closeProject() {
|
||||
project.close();
|
||||
}
|
||||
|
||||
public StarterDependenciesIntegrationTests(String starter) {
|
||||
this.buildArguments = new String[] { "-Pstarter=" + starter,
|
||||
"-PbootVersion=" + bootVersion, "-PspringVersion=" + springVersion };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void commonsLoggingIsNotATransitiveDependency() throws IOException {
|
||||
runBuildForTask("checkCommonsLogging");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oldSpringModulesAreNotTransitiveDependencies() throws IOException {
|
||||
runBuildForTask("checkSpring");
|
||||
}
|
||||
|
||||
private void runBuildForTask(String task) {
|
||||
try {
|
||||
project.newBuild().forTasks(task).withArguments(this.buildArguments).run();
|
||||
}
|
||||
catch (BuildException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
bootRun {
|
||||
addResources = Boolean.valueOf(project.addResources)
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
jar {
|
||||
baseName = 'classifier-extension'
|
||||
}
|
||||
|
||||
springBoot {
|
||||
classifier = 'exec'
|
||||
mainClass = 'demo.Application'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.springframework:spring-core"
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
jar {
|
||||
baseName = 'classifier'
|
||||
}
|
||||
|
||||
bootRepackage {
|
||||
classifier = 'exec'
|
||||
mainClass = 'demo.Application'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.springframework:spring-core"
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compile 'org.springframework.boot:spring-boot-starter-freemarker'
|
||||
compile 'org.springframework.boot:spring-boot-starter-web'
|
||||
compile 'org.springframework.boot:spring-boot-devtools'
|
||||
compile files("foo.jar")
|
||||
}
|
||||
|
||||
springBoot {
|
||||
mainClass = 'foo.bar.Baz'
|
||||
}
|
||||
|
||||
if (project.properties['taskExecutable']) {
|
||||
bootRepackage.executable = Boolean.valueOf(project.taskExecutable)
|
||||
}
|
||||
|
||||
if (project.properties['extensionExecutable']) {
|
||||
springBoot.executable = Boolean.valueOf(project.extensionExecutable)
|
||||
}
|
||||
|
||||
if (project.properties['taskProperties']) {
|
||||
bootRepackage.executable = true
|
||||
bootRepackage.embeddedLaunchScriptProperties = ['initInfoProvides': '__task__']
|
||||
}
|
||||
|
||||
if (project.properties['extensionProperties']) {
|
||||
bootRepackage.executable = true
|
||||
springBoot.embeddedLaunchScriptProperties = ['initInfoProvides': '__extension__']
|
||||
}
|
||||
|
||||
if (project.properties['taskScript']) {
|
||||
bootRepackage.embeddedLaunchScript = file('task.script')
|
||||
}
|
||||
|
||||
if (project.properties['extensionScript']) {
|
||||
springBoot.embeddedLaunchScript = file('extension.script')
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
Custom extension script
|
||||
@@ -1 +0,0 @@
|
||||
Custom task script
|
||||
@@ -1,30 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
group = 'flatdir'
|
||||
version = '0.0.0'
|
||||
|
||||
bootRun {
|
||||
main = 'Foo'
|
||||
}
|
||||
|
||||
jar {
|
||||
baseName = 'flatdir'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
flatDir( dirs:'lib' )
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile ':foo:1.0.0'
|
||||
}
|
||||
Binary file not shown.
@@ -1,33 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'application'
|
||||
|
||||
group = 'installer'
|
||||
version = '0.0.0'
|
||||
|
||||
bootRun {
|
||||
main = 'org.springframework.boot.SpringApplication'
|
||||
}
|
||||
|
||||
jar {
|
||||
baseName = 'install-app'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.springframework.boot:spring-boot-starter"
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
group = 'installer'
|
||||
version = '0.0.0'
|
||||
|
||||
install {
|
||||
repositories.mavenInstaller {
|
||||
pom.project {
|
||||
parent {
|
||||
groupId 'org.springframework.boot'
|
||||
artifactId 'spring-boot-starter-parent'
|
||||
version "${project.bootVersion}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
baseName = 'installer'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.springframework.boot:spring-boot-starter"
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
group = 'installer'
|
||||
version = '0.0.0'
|
||||
|
||||
if (project.hasProperty('bootRunMain')) {
|
||||
bootRun {
|
||||
main = 'org.springframework.boot.SpringApplication'
|
||||
}
|
||||
}
|
||||
|
||||
if (project.hasProperty('nonJavaExecRun')) {
|
||||
task run { }
|
||||
}
|
||||
|
||||
|
||||
jar {
|
||||
baseName = 'installer'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.springframework.boot:spring-boot-starter"
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compile 'com.google.guava:guava:16.0'
|
||||
runtime 'com.google.guava:guava:18.0'
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
overriddenByDependencies = false
|
||||
}
|
||||
|
||||
springBoot {
|
||||
mainClass = 'foo.bar.Baz'
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
subprojects {
|
||||
apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compile rootProject.files {'lib/foo.jar'}
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
springBoot {
|
||||
mainClass = 'foo.bar.Baz'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':one')
|
||||
compile project(':two')
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -1,3 +0,0 @@
|
||||
|
||||
include 'one'
|
||||
include 'two'
|
||||
@@ -1,25 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
project(':projectA') {
|
||||
apply plugin: 'org.springframework.boot'
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
runtime project(':projectB')
|
||||
}
|
||||
bootRepackage {
|
||||
mainClass 'com.foo.Bar'
|
||||
}
|
||||
}
|
||||
|
||||
project(':projectB') {
|
||||
apply plugin: 'java'
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
include 'projectA', 'projectB'
|
||||
@@ -1,40 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
project('main') {
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':common')
|
||||
}
|
||||
|
||||
springBoot {
|
||||
mainClass = 'foo.bar.Baz'
|
||||
}
|
||||
}
|
||||
|
||||
project('common') {
|
||||
apply plugin: 'java'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "commons-logging:commons-logging:1.1.3"
|
||||
compile files { "lib/foo.jar" }
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,3 +0,0 @@
|
||||
|
||||
include 'main'
|
||||
include 'common'
|
||||
@@ -1,30 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
group = 'nojar'
|
||||
version = '0.0.0'
|
||||
|
||||
jar {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
bootRepackage {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'org.springframework.boot:spring-boot-starter'
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compile 'org.springframework.boot:spring-boot-starter-freemarker'
|
||||
compile 'org.springframework.boot:spring-boot-starter-web'
|
||||
compile 'org.springframework.boot:spring-boot-devtools'
|
||||
compile files("foo.jar")
|
||||
}
|
||||
|
||||
springBoot {
|
||||
if (!project.hasProperty("noMainClass")) {
|
||||
mainClass = 'foo.bar.Baz'
|
||||
}
|
||||
if (project.hasProperty("excludeDevtoolsOnExtension")) {
|
||||
excludeDevtools = Boolean.valueOf(project.excludeDevtoolsOnExtension)
|
||||
}
|
||||
}
|
||||
|
||||
bootRepackage {
|
||||
enabled = Boolean.valueOf(project.repackage)
|
||||
if (project.hasProperty("excludeDevtoolsOnBootRepackage")) {
|
||||
excludeDevtools = Boolean.valueOf(project.excludeDevtoolsOnBootRepackage)
|
||||
}
|
||||
}
|
||||
|
||||
task customJar(type: Jar) {
|
||||
archiveName = 'custom.jar'
|
||||
from sourceSets.main.output
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
}
|
||||
|
||||
task customRepackagedJar(type: BootRepackage, dependsOn: customJar) {
|
||||
withJarTask = customJar
|
||||
}
|
||||
|
||||
task customRepackagedJarWithStringReference(type: BootRepackage, dependsOn: customJar) {
|
||||
withJarTask = 'customJar'
|
||||
}
|
||||
|
||||
task customRepackagedJarWithOwnMainClass(type: BootRepackage, dependsOn: customJar) {
|
||||
withJarTask = customJar
|
||||
mainClass = 'foo.bar.Baz'
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
|
||||
classpath("org.springframework:springloaded:${project.springLoadedVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'application'
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter")
|
||||
}
|
||||
|
||||
applicationDefaultJvmArgs = [
|
||||
"-DSOME_ARG=someValue"
|
||||
]
|
||||
|
||||
jar {
|
||||
baseName = 'spring-loaded-jvm-args'
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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 test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PrintWriter writer = new PrintWriter(new FileWriter(new File("build/output.txt")));
|
||||
for (String argument: ManagementFactory.getRuntimeMXBean().getInputArguments()) {
|
||||
writer.println(argument);
|
||||
}
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
|
||||
classpath("org.springframework:springloaded:${project.springLoadedVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-starter")
|
||||
}
|
||||
|
||||
jar {
|
||||
baseName = 'spring-loaded-old-gradle'
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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 test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PrintWriter writer = new PrintWriter(new FileWriter(new File("build/output.txt")));
|
||||
for (String argument: ManagementFactory.getRuntimeMXBean().getInputArguments()) {
|
||||
writer.println(argument);
|
||||
}
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
import org.gradle.api.artifacts.result.UnresolvedDependencyResult;
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
configurations {
|
||||
springBootStarter
|
||||
}
|
||||
|
||||
dependencies {
|
||||
springBootStarter "org.springframework.boot:${project.starter}:${project.bootVersion}"
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
task checkCommonsLogging {
|
||||
doFirst {
|
||||
def commonsLogging = resolvedDependencies
|
||||
.find { it.selected.id.group == 'commons-logging' }
|
||||
if (commonsLogging) {
|
||||
throw new GradleException("${project.starter} pulls in commons-logging")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task checkSpring {
|
||||
doFirst {
|
||||
def wrongSpring = resolvedDependencies
|
||||
.findAll{it.selected.id.group == 'org.springframework'}
|
||||
.findAll{it.selected.id.version != project.springVersion}
|
||||
.collect {it.selected.id}
|
||||
if (wrongSpring) {
|
||||
throw new GradleException("${project.starter} pulled in ${wrongSpring as Set}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def getResolvedDependencies() {
|
||||
def allDependencies = configurations.springBootStarter.incoming
|
||||
.resolutionResult.allDependencies
|
||||
.split { it instanceof UnresolvedDependencyResult }
|
||||
|
||||
def unresolved = allDependencies.first()
|
||||
def resolved = allDependencies.last()
|
||||
if (unresolved) {
|
||||
throw new GradleException("Resolution of ${project.starter} failed: ${unresolved}")
|
||||
}
|
||||
resolved
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import org.gradle.api.artifacts.result.UnresolvedDependencyResult;
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'war'
|
||||
|
||||
dependencies {
|
||||
compile 'org.springframework.boot:spring-boot-starter-freemarker'
|
||||
providedRuntime "org.springframework.boot:spring-boot-starter-$servletContainer"
|
||||
}
|
||||
|
||||
springBoot {
|
||||
mainClass = 'foo.bar.Baz'
|
||||
}
|
||||
@@ -199,46 +199,6 @@
|
||||
<artifactId>aether-util</artifactId>
|
||||
<version>${aether.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-base-services</artifactId>
|
||||
<version>${gradle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-base-services-groovy</artifactId>
|
||||
<version>${gradle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-core</artifactId>
|
||||
<version>${gradle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-language-java</artifactId>
|
||||
<version>${gradle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-language-jvm</artifactId>
|
||||
<version>${gradle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-platform-jvm</artifactId>
|
||||
<version>${gradle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-plugins</artifactId>
|
||||
<version>${gradle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-process-services</artifactId>
|
||||
<version>${gradle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-runtime</artifactId>
|
||||
|
||||
@@ -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' }
|
||||
|
||||
83
spring-boot-tools/spring-boot-gradle-plugin/build.gradle
Normal file
83
spring-boot-tools/spring-boot-gradle-plugin/build.gradle
Normal file
@@ -0,0 +1,83 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'eclipse'
|
||||
id 'org.sonarqube' version '2.2.1'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
def addDependency(configurationName, dependency) {
|
||||
def coordinates = [
|
||||
'group': dependency.groupId.text(),
|
||||
'name': dependency.artifactId.text(),
|
||||
'version': dependency.version.text()
|
||||
]
|
||||
dependencies {
|
||||
add configurationName, coordinates
|
||||
}
|
||||
}
|
||||
|
||||
def effectivePomFile = file('target/effective-pom.xml')
|
||||
if (effectivePomFile.file) {
|
||||
def pom = new XmlSlurper().parseText(file('target/effective-pom.xml').text)
|
||||
pom.dependencies.dependency.each { dependency ->
|
||||
def scope = dependency.scope.text()
|
||||
if (scope == 'compile') {
|
||||
addDependency scope, dependency
|
||||
}
|
||||
else if (scope == 'test') {
|
||||
addDependency 'testCompile', dependency
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile localGroovy()
|
||||
compile gradleApi()
|
||||
testCompile gradleTestKit()
|
||||
testCompile 'org.apache.commons:commons-compress:1.13'
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Implementation-Version': (version ? version : 'unknown')
|
||||
}
|
||||
}
|
||||
|
||||
eclipseJdt {
|
||||
inputFile = rootProject.file('../../eclipse/org.eclipse.jdt.core.prefs')
|
||||
doLast {
|
||||
project.file('.settings/org.eclipse.jdt.ui.prefs').withWriter { writer ->
|
||||
writer << file('../../eclipse/org.eclipse.jdt.ui.prefs').text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
javadoc {
|
||||
options {
|
||||
author()
|
||||
stylesheetFile = file('src/main/javadoc/spring-javadoc.css')
|
||||
links = [
|
||||
'http://docs.oracle.com/javase/8/docs/api/',
|
||||
'https://docs.gradle.org/current/javadoc/'
|
||||
]
|
||||
}
|
||||
title = "${project.description} $version API"
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar) {
|
||||
classifier = "javadoc"
|
||||
from javadoc
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.gradle.daemon=false
|
||||
BIN
spring-boot-tools/spring-boot-gradle-plugin/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
spring-boot-tools/spring-boot-gradle-plugin/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
spring-boot-tools/spring-boot-gradle-plugin/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
spring-boot-tools/spring-boot-gradle-plugin/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
#Thu Mar 16 20:08:41 GMT 2017
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-bin.zip
|
||||
172
spring-boot-tools/spring-boot-gradle-plugin/gradlew
vendored
Executable file
172
spring-boot-tools/spring-boot-gradle-plugin/gradlew
vendored
Executable file
@@ -0,0 +1,172 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save ( ) {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
84
spring-boot-tools/spring-boot-gradle-plugin/gradlew.bat
vendored
Normal file
84
spring-boot-tools/spring-boot-gradle-plugin/gradlew.bat
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -7,6 +7,7 @@
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-boot-gradle-plugin</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>Spring Boot Gradle Plugin</name>
|
||||
<description>Spring Boot Gradle Plugin</description>
|
||||
<url>http://projects.spring.io/spring-boot/</url>
|
||||
@@ -16,9 +17,9 @@
|
||||
</organization>
|
||||
<properties>
|
||||
<main.basedir>${basedir}/../..</main.basedir>
|
||||
<gradle.executable>./gradlew</gradle.executable>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- Compile -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-loader-tools</artifactId>
|
||||
@@ -27,58 +28,223 @@
|
||||
<groupId>io.spring.gradle</groupId>
|
||||
<artifactId>dependency-management-plugin</artifactId>
|
||||
</dependency>
|
||||
<!-- Provided -->
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-base-services</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-language-java</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-language-jvm</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-platform-jvm</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-plugins</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gradle</groupId>
|
||||
<artifactId>gradle-process-services</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<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>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-help-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>effective-pom</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<output>${project.build.directory}/effective-pom.xml</output>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>gradle</id>
|
||||
<phase>prepare-package</phase>
|
||||
<configuration>
|
||||
<executable>${gradle.executable}</executable>
|
||||
<arguments>
|
||||
<argument>clean</argument>
|
||||
<argument>build</argument>
|
||||
<argument>-Pversion=${project.version}</argument>
|
||||
<argument>-Pdescription=${project.description}</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.12</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-artifacts</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>attach-artifact</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifacts>
|
||||
<artifact>
|
||||
<file>build/libs/${project.artifactId}-${project.version}.jar</file>
|
||||
<type>jar</type>
|
||||
</artifact>
|
||||
<artifact>
|
||||
<file>build/libs/${project.artifactId}-${project.version}-javadoc.jar</file>
|
||||
<type>jar</type>
|
||||
<classifier>javadoc</classifier>
|
||||
</artifact>
|
||||
<artifact>
|
||||
<file>build/libs/${project.artifactId}-${project.version}-sources.jar</file>
|
||||
<type>jar</type>
|
||||
<classifier>sources</classifier>
|
||||
</artifact>
|
||||
</artifacts>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>windows</id>
|
||||
<activation>
|
||||
<os>
|
||||
<name>windows</name>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<gradle.executable>gradlew.bat</gradle.executable>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>full</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>ant-contrib</groupId>
|
||||
<artifactId>ant-contrib</artifactId>
|
||||
<version>1.0b3</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>ant</groupId>
|
||||
<artifactId>ant</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.ant</groupId>
|
||||
<artifactId>ant-nodeps</artifactId>
|
||||
<version>1.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.tigris.antelope</groupId>
|
||||
<artifactId>antelopetasks</artifactId>
|
||||
<version>3.2.10</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>set-up-maven-properties</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<exportAntProperties>true</exportAntProperties>
|
||||
<target>
|
||||
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
|
||||
<taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask" />
|
||||
<var name="version-type" value="${project.version}" />
|
||||
<propertyregex property="version-type" override="true" input="${version-type}" regexp=".*\.(.*)" replace="\1" />
|
||||
<propertyregex property="version-type" override="true" input="${version-type}" regexp="(M)\d+" replace="MILESTONE" />
|
||||
<propertyregex property="version-type" override="true" input="${version-type}" regexp="(RC)\d+" replace="MILESTONE" />
|
||||
<propertyregex property="version-type" override="true" input="${version-type}" regexp="BUILD-(.*)" replace="SNAPSHOT" />
|
||||
<var name="github-tag" value="v${project.version}" />
|
||||
<propertyregex property="github-tag" override="true" input="${github-tag}" regexp=".*SNAPSHOT" replace="master" />
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>package-docs-zip</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<zip destfile="${project.build.directory}/${project.artifactId}-${project.version}-docs.zip">
|
||||
<zipfileset src="build/libs/${project.artifactId}-${project.version}-javadoc.jar" prefix="api" />
|
||||
<zipfileset dir="${project.build.directory}/generated-docs" prefix="reference" />
|
||||
</zip>
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctor-maven-plugin</artifactId>
|
||||
<version>1.5.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-html-documentation</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>process-asciidoc</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<backend>html</backend>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>generate-pdf-documentation</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>process-asciidoc</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<backend>pdf</backend>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<attributes>
|
||||
<version-type>${version-type}</version-type>
|
||||
<version>${project.version}</version>
|
||||
</attributes>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctorj-pdf</artifactId>
|
||||
<version>1.5.0-alpha.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-zip</id>
|
||||
<goals>
|
||||
<goal>attach-artifact</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifacts>
|
||||
<artifact>
|
||||
<file>${project.build.directory}/${project.artifactId}-${project.version}-docs.zip</file>
|
||||
<type>zip</type>
|
||||
<classifier>docs</classifier>
|
||||
</artifact>
|
||||
</artifacts>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
[[getting-started]]
|
||||
== Getting started
|
||||
|
||||
To get started with the plugin it needs to be applied to your project.
|
||||
|
||||
ifeval::["{version-type}" == "RELEASE"]
|
||||
The plugin is https://plugins.gradle.org/plugin/org.springframework.boot[published to
|
||||
Gradle's plugin portal] and can be applied using the `plugins` block:
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
include::../gradle/getting-started/apply-plugin-release.gradle[]
|
||||
----
|
||||
endif::[]
|
||||
ifeval::["{version-type}" == "MILESTONE"]
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
include::../gradle/getting-started/apply-plugin-milestone.gradle[]
|
||||
----
|
||||
endif::[]
|
||||
ifeval::["{version-type}" == "SNAPSHOT"]
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
include::../gradle/getting-started/apply-plugin-snapshot.gradle[]
|
||||
----
|
||||
endif::[]
|
||||
|
||||
Applied in isolation the plugin makes few changes to a project. Instead, the plugin
|
||||
detects when certain other plugins are applied and reacts accordingly. For example, when
|
||||
the `java` plugin is applied a task for building an executable jar is automatically
|
||||
configured.
|
||||
|
||||
A typical Spring Boot project will apply the {groovy-plugin}[`groovy`],
|
||||
{java-plugin}java_plugin.html[`java`], or {kotlin-plugin}[`org.jetbrains.kotlin.jvm`]
|
||||
plugin and the {dependency-management-plugin}[`io.spring.dependency-management`] plugin as
|
||||
a minimum. For example:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
include::../gradle/getting-started/typical-plugins.gradle[tags=apply]
|
||||
----
|
||||
|
||||
To learn more about how the Spring Boot plugin behaves when other plugins are applied
|
||||
please see the section on <<reacting-to-other-plugins, reacting to other plugins>>.
|
||||
@@ -0,0 +1,48 @@
|
||||
= Spring Boot Gradle Plugin Reference Guide
|
||||
Andy Wilkinson
|
||||
:doctype: book
|
||||
:toc: left
|
||||
:toclevels: 4
|
||||
:source-highlighter: prettify
|
||||
:numbered:
|
||||
:icons: font
|
||||
:hide-uri-scheme:
|
||||
:dependency-management-plugin: https://github.com/spring-gradle-plugins/dependency-management-plugin
|
||||
:dependency-management-plugin-documentation: {dependency-management-plugin}/blob/master/README.md
|
||||
:gradle-userguide: http://www.gradle.org/docs/current/userguide
|
||||
:gradle-dsl: https://docs.gradle.org/current/dsl
|
||||
:application-plugin: {gradle-userguide}/application_plugin.html
|
||||
:groovy-plugin: {gradle-userguide}/groovy_plugin.html
|
||||
:java-plugin: {gradle-userguide}/java_plugin.html
|
||||
:war-plugin: {gradle-userguide}/war_plugin.html
|
||||
:maven-plugin: {gradle-userguide}/maven_plugin.html
|
||||
:maven-publish-plugin: {gradle-userguide}/maven_publish_plugin.html
|
||||
:software-component: {gradle-userguide}/software_model_extend.html
|
||||
:kotlin-plugin: https://kotlinlang.org/docs/reference/using-gradle.html
|
||||
:spring-boot-docs: https://docs.spring.io/spring-boot/{version}
|
||||
:api-documentation: {spring-boot-docs}/gradle-plugin/api
|
||||
:spring-boot-reference: {spring-boot-docs}/reference/htmlsingle
|
||||
:build-info-javadoc: {api-documentation}/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.html
|
||||
:boot-jar-javadoc: {api-documentation}/org/springframework/boot/gradle/tasks/bundling/BootJar.html
|
||||
:boot-war-javadoc: {api-documentation}/org/springframework/boot/gradle/tasks/bundling/BootWar.html
|
||||
:boot-run-javadoc: {api-documentation}/org/springframework/boot/gradle/tasks/run/BootRun.html
|
||||
:github-code: https://github.com/spring-projects/spring-boot/tree/{github-tag}
|
||||
|
||||
|
||||
|
||||
[[introduction]]
|
||||
== Introduction
|
||||
|
||||
The Spring Boot Gradle Plugin provides Spring Boot support in https://gradle.org[Gradle],
|
||||
allowing you to package executable jar or war archives, run Spring Boot applications, and
|
||||
use the dependency management provided by `spring-boot-dependencies`. Spring Boot's
|
||||
Gradle plugin requires Gradle 3.4 or later.
|
||||
|
||||
In addition to this user guide, {api-documentation}[API documentation] is also available.
|
||||
|
||||
include::getting-started.adoc[]
|
||||
include::managing-dependencies.adoc[]
|
||||
include::packaging.adoc[]
|
||||
include::running.adoc[]
|
||||
include::integrating-with-actuator.adoc[]
|
||||
include::reacting.adoc[]
|
||||
@@ -0,0 +1,55 @@
|
||||
[[integrating-with-actuator]]
|
||||
== Integrating with Actuator
|
||||
|
||||
|
||||
[[integrating-with-actuator-build-info]]
|
||||
=== Generating build information
|
||||
|
||||
Spring Boot Actuator's `info` endpoint automatically publishes information about your
|
||||
build in the presence of a `META-INF/build-info.properties` file. A
|
||||
{build-info-javadoc}[`BuildInfo`] task is provided to generate this file. The easiest way
|
||||
to use the task is via the plugin's DSL:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/integrating-with-actuator/build-info-basic.gradle[tags=build-info]
|
||||
----
|
||||
|
||||
This will configure a {build-info-javadoc}[`BuildInfo`] task named `bootBuildInfo` and, if
|
||||
it exists, make the Java plugin's `classes` task depend upon it. The task's desination
|
||||
directory will be `META-INF` in the output directory of the main source set's resources
|
||||
(typically `build/resources/main`).
|
||||
|
||||
By default, the generated build information is derived from the project:
|
||||
|
||||
|===
|
||||
| Property | Default value
|
||||
|
||||
| `build.artifact`
|
||||
| The base name of the `bootJar` or `bootWar` task, or `unspecified` if no such task
|
||||
exists
|
||||
|
||||
| `build.group`
|
||||
| The group of the project
|
||||
|
||||
| `build.name`
|
||||
| The name of the project
|
||||
|
||||
| `build.version`
|
||||
| The version of the project
|
||||
|
||||
|===
|
||||
|
||||
The properties can be customized using the DSL:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/integrating-with-actuator/build-info-custom-values.gradle[tags=custom-values]
|
||||
----
|
||||
|
||||
Additional properties can also be added to the build information:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/integrating-with-actuator/build-info-additional.gradle[tags=additional]
|
||||
----
|
||||
@@ -0,0 +1,46 @@
|
||||
[[managing-dependencies]]
|
||||
== Managing dependencies
|
||||
|
||||
When you apply the {dependency-management-plugin}[`io.spring.dependency-management`]
|
||||
plugin, Spring Boot's plugin will
|
||||
automatically <<reacting-to-other-plugins-dependency-management,import the
|
||||
`spring-boot-dependencies` bom>> from the version of Spring Boot that you are using.
|
||||
This provides a similar dependency management experience to the one that's enjoyed by
|
||||
Maven users. For example, it allows you to omit version numbers when declaring
|
||||
dependencies that are managed in the bom. To make use of this functionality, simply
|
||||
declare dependencies in the usual way but omit the version number:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/managing-dependencies/dependencies.gradle[tags=dependencies]
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[managing-dependencies-customizing]]
|
||||
=== Customizing managed versions
|
||||
|
||||
The `spring-boot-dependencies` bom that is automatically imported when the dependency
|
||||
management plugin is applied uses properties to control the versions of the dependencies
|
||||
that it manages. Please refer to the {github-code}/spring-boot-dependencies/pom.xml[bom]
|
||||
for a complete list of these properties.
|
||||
|
||||
To customize a managed version you set its corresponding property. For example, to
|
||||
customize the version of SLF4J which is controlled by the `slf4j.version` property:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/managing-dependencies/custom-version.gradle[tags=custom-version]
|
||||
----
|
||||
|
||||
WARNING: Each Spring Boot release is designed and tested against a specific set of
|
||||
third-party dependencies. Overriding versions may cause compatibility issues and should
|
||||
be done with care.
|
||||
|
||||
|
||||
|
||||
[[managing-dependencies-learning-more]]
|
||||
=== Learning more
|
||||
|
||||
To learn more about the capabilities of the dependency management plugin, please refer to
|
||||
its {dependency-management-plugin-documentation}[documentation].
|
||||
@@ -0,0 +1,167 @@
|
||||
[[packaging-executable]]
|
||||
== Packaging executable archives
|
||||
|
||||
The plugin can create executable archives (jar files and war files) that contain all of
|
||||
an application's dependencies and can then be run with `java -jar`.
|
||||
|
||||
|
||||
|
||||
[[packaging-executable-jars]]
|
||||
=== Packaging executable jars
|
||||
|
||||
Executable jars can be built using the `bootJar` task. The task is automatically created
|
||||
when the `java` plugin is applied and is an instance of {boot-jar-javadoc}[`BootJar`].
|
||||
|
||||
|
||||
|
||||
[[packaging-executable-wars]]
|
||||
=== Packaging executable wars
|
||||
|
||||
Executable wars can be built using the `bootWar` task. The task is automatically created
|
||||
when the `war` plugin is applied and is an instance of {boot-war-javadoc}[`BootWar`].
|
||||
|
||||
|
||||
|
||||
[[packaging-executable-wars-deployable]]
|
||||
==== Packaging executable and deployable wars
|
||||
|
||||
A war file can be packaged such that it can be executed using `java -jar` and deployed
|
||||
to an external container. To do so, the embedded servlet container dependencies should
|
||||
be added to the `providedRuntime` configuration, for example:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/packaging/war-container-dependency.gradle[tags=dependencies]
|
||||
----
|
||||
|
||||
This ensures that they are package in the war file's `WEB-INF/lib-provided` directory
|
||||
from where they will not conflict with the external container's own classes.
|
||||
|
||||
NOTE: `providedRuntime` is prefered to Gradle's `compileOnly` configuration as, among
|
||||
other limitations, `compileOnly` dependencies are not on the test classpath so any
|
||||
web-based integration tests will fail.
|
||||
|
||||
|
||||
|
||||
[[packaging-executable-configuring]]
|
||||
=== Configuring executable archive packaging
|
||||
|
||||
The {boot-jar-javadoc}[`BootJar`] and {boot-war-javadoc}[`BootWar`] tasks are subclasses
|
||||
of Gradle's `Jar` and `War` tasks respectively. As a result, all of the standard
|
||||
configuration options that are available when packaging a jar or war are also available
|
||||
when packaging an executable jar or war. A number of configuration options that are
|
||||
specific to executable jars and wars are also provided.
|
||||
|
||||
|
||||
[[packaging-executable-configuring-main-class]]
|
||||
==== Configuring the main class
|
||||
|
||||
By default, the executable archive's main class will be configured automatically by
|
||||
looking for a class with a `public static void main(String[])` method in directories on
|
||||
the task's classpath.
|
||||
|
||||
The main class can also be configured explicity using the task's `mainClass` property:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/packaging/boot-jar-main-class.gradle[tags=main-class]
|
||||
----
|
||||
|
||||
Alternatively, if the {application-plugin}[`application` plugin] has been applied
|
||||
its `mainClassName` project property can be used:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/packaging/application-plugin-main-class.gradle[tags=main-class]
|
||||
----
|
||||
|
||||
Lastly, the `Start-Class` attribute can be configured on the task's manifest:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/packaging/boot-jar-manifest-main-class.gradle[tags=main-class]
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[packaging-executable-configuring-excluding-devtools]]
|
||||
==== Excluding Devtools
|
||||
|
||||
By default, Spring Boot's Devtools module,
|
||||
`org.springframework.boot:spring-boot-devtools`, will be excluded from an executable jar
|
||||
or war. If you want to include Devtools in your archive set the `excludeDevtools`
|
||||
property to `true`:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/packaging/boot-war-include-devtools.gradle[tags=include-devtools]
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[packaging-executable-configuring-unpacking]]
|
||||
==== Configuring libraries that require unpacking
|
||||
|
||||
Most libraries can be used directly when nested in an executable archive, however certain
|
||||
libraries can have problems. For example, JRuby includes its own nested jar support which
|
||||
assumes that `jruby-complete.jar` is always directly available on the file system.
|
||||
|
||||
To deal with any problematic libraries, an executable archive can be configured to unpack
|
||||
specific nested jars to a temporary folder when the executable archive is run. Libraries
|
||||
can be identified as requiring unpacking using Ant-style patterns that match against
|
||||
the absolute path of the source jar file:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/packaging/boot-jar-requires-unpack.gradle[tags=requires-unpack]
|
||||
----
|
||||
|
||||
For more control a closure can also be used. The closure is passed a `FileTreeElement`
|
||||
and should return a `boolean` indicating whether or not unpacking is required.
|
||||
|
||||
|
||||
|
||||
[[packaging-executable-configuring-launch-script]]
|
||||
==== Making an archive fully executable
|
||||
|
||||
Spring Boot provides support for fully executable archives. An archive is made fully
|
||||
executable by prepending a shell script that knows how to launch the application. On
|
||||
Unix-like platforms, this launch script allows the archive to be run directly like any
|
||||
other executable or to be installed as a service.
|
||||
|
||||
To use this feature, the inclusion of the launch script must be enabled:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/packaging/boot-jar-include-launch-script.gradle[tags=include-launch-script]
|
||||
----
|
||||
|
||||
This will add Spring Boot's default launch script to the archive. The default launch
|
||||
script includes several properties with sensible default values. The values can be
|
||||
customized using the `properties` property:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/packaging/boot-jar-launch-script-properties.gradle[tags=launch-script-properties]
|
||||
----
|
||||
|
||||
If the default launch script does not meet your needs, the `script` property can be used
|
||||
to provide a custom launch script:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/packaging/boot-jar-custom-launch-script.gradle[tags=custom-launch-script]
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[packaging-executable-configuring-properties-launcher]]
|
||||
==== Using the `PropertiesLauncher`
|
||||
|
||||
To use the `PropertiesLauncher` to launch an executable jar or war, configure the task's
|
||||
manifest to set the `Main-Class` attribute:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/packaging/boot-war-properties-launcher.gradle[tags=properties-launcher]
|
||||
----
|
||||
@@ -0,0 +1,43 @@
|
||||
[[publishing-your-application]]
|
||||
== Publishing your application
|
||||
|
||||
|
||||
|
||||
[[publishing-your-application-maven]]
|
||||
=== Publishing with the `maven` plugin
|
||||
|
||||
When the {maven-plugin}[`maven` plugin] is applied, an `Upload` task for the
|
||||
`bootArchives` configuration named `uploadBootArchives` is automatically created. By
|
||||
default, the `bootArchives` configuration contains the archive produced by the `bootJar`
|
||||
or `bootWar` task. The `uploadBootArchives` task can be configured to publish the archive
|
||||
to a Maven repository:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/publishing/maven.gradle[tags=upload]
|
||||
----
|
||||
|
||||
[[publishing-your-application-maven-publish]]
|
||||
=== Publishing with the `maven-publish` plugin
|
||||
|
||||
When the {java-plugin}[`java` plugin] is applied Spring Boot automatically creates a
|
||||
{software-component}[software component] named `bootJava`. Similarly, when the `war`
|
||||
plugin is applied, a software component named `bootWeb` is created. `bootJava` contains
|
||||
the archive produced by the `bootJar` task and `bootWeb` contains the archive provided by
|
||||
the `bootWar` task. The components can be used with the
|
||||
{maven-publish-plugin}[`maven-publish` plugin] to publish the archive, for example:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/publishing/maven-publish.gradle[tags=publishing]
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[publishing-your-application-distrubution]]
|
||||
=== Distributing with the `application` plugin
|
||||
|
||||
When the {application-plugin}[`application` plugin] is applied a distribution named
|
||||
`boot` is created. This distribution contains the archive produced by the `bootJar` or
|
||||
`bootWar` task and scripts to launch it on Unix-like platforms and Windows. Zip and tar
|
||||
distributions can be built by the `bootDistZip` and `bootDistTar` tasks respectively.
|
||||
@@ -0,0 +1,78 @@
|
||||
[[reacting-to-other-plugins]]
|
||||
== Reacting to other plugins
|
||||
|
||||
When another plugin is applied the Spring Boot plugin reacts by making various changes
|
||||
to the project's configuration. This section describes those changes.
|
||||
|
||||
[[reacting-to-other-plugins-java]]
|
||||
=== Reacting to the Java plugin
|
||||
|
||||
When Gradle's {java-plugin}[`java` plugin] is applied to a project, the Spring Boot
|
||||
plugin:
|
||||
|
||||
1. Creates a {boot-jar-javadoc}[`BootJar`] task named `bootJar` that will create an
|
||||
executable, fat jar for the project. The jar will contain everything on the runtime
|
||||
classpath of the main source set; classes are packaged in `BOOT-INF/classes` and jars
|
||||
are packaged in `BOOT-INF/lib`
|
||||
2. Creates a {software-component}[software component] named `bootJava` that contains the
|
||||
archive produced by the `bootJar` task.
|
||||
3. Creates a {boot-run-javadoc}[`BootRun`] task named `bootRun` that can be used to run
|
||||
your application.
|
||||
4. Creates a configuration named `bootArchives` that contains the artifact produced by
|
||||
the `bootJar` task.
|
||||
5. Configures any `JavaCompile` tasks with no configured encoding to use `UTF-8`.
|
||||
|
||||
|
||||
|
||||
[[reacting-to-other-plugins-war]]
|
||||
=== Reacting to the war plugin
|
||||
|
||||
When Gradle's {war-plugin}[`war` plugin] is applied to a project, the Spring Boot plugin:
|
||||
|
||||
1. Creates a {boot-war-javadoc}[`BootWar`] task named `bootWar` that will create an
|
||||
executable, fat war for the project. In addition to the standard packaging, everything
|
||||
in the `providedRuntime` configuration will be packaged in `WEB-INF/lib-provided`.
|
||||
2. Creates a {software-component}[software component] named `bootWeb` that contains the
|
||||
archive produced by the `bootWar` task.
|
||||
3. Configures the `bootArchives` configuration to contain the artifact produced by the
|
||||
`bootWar` task.
|
||||
|
||||
|
||||
|
||||
[[reacting-to-other-plugins-dependency-management]]
|
||||
=== Reacting to the dependency management plugin
|
||||
|
||||
When the {dependency-management-plugin}[`io.spring.dependency-management` plugin] is
|
||||
applied to a project, the Spring Boot plugin will automatically import the
|
||||
`spring-boot-dependencies` bom.
|
||||
|
||||
|
||||
|
||||
[[reacting-to-other-plugins-application]]
|
||||
=== Reacting to the application plugin
|
||||
|
||||
When Gradle's {application-plugin}[`application` plugin] is applied to a project, the
|
||||
Spring Boot plugin:
|
||||
|
||||
1. Creates a `CreateStartScripts` task named `bootStartScripts` that will creates scripts
|
||||
that launch the artifact in the `bootArchives` configuration using `java -jar`.
|
||||
2. Creates a new distribution named `boot` and configures it to contain the artifact in
|
||||
the `bootArchives` configuration in its `lib` directory and the start scripts in its
|
||||
`bin` directory.
|
||||
3. Configures the `bootRun` task to use the `mainClassName` property as a convention for
|
||||
its `main` property.
|
||||
4. Configures the `bootRun` task to use the `applicationDefaultJvmArgs` property as a
|
||||
convention for its `jvmArgs` property.
|
||||
5. Configures the `bootJar` task to use the `mainClassName` property as a convention for
|
||||
the `Start-Class` entry in its manifest.
|
||||
6. Configures the `bootWar` task to use the `mainClassName` property as a convention for
|
||||
the `Start-Class` entry in its manifest.
|
||||
|
||||
|
||||
|
||||
[[reacting-to-other-plugins-maven]]
|
||||
=== Reacting to the Maven plugin
|
||||
|
||||
When Gradle's {maven-plugin}[`maven` plugin] is applied to a project, the Spring Boot
|
||||
plugin will configure the `uploadBootArchives` `Upload` task to ensure that no
|
||||
dependencies are declared in the pom that it generates.
|
||||
@@ -0,0 +1,49 @@
|
||||
[[running-your-application]]
|
||||
== Running your application with Gradle
|
||||
|
||||
To run your application without first building an archive use the `bootRun` task:
|
||||
|
||||
[source,bash,indent=0,subs="verbatim"]
|
||||
----
|
||||
$ ./gradlew bootRun
|
||||
----
|
||||
|
||||
The `bootRun` task is an instance of
|
||||
{boot-run-javadoc}[`BootRun`] which is a `JavaExec` subclass. As such, all of the
|
||||
{gradle-dsl}/org.gradle.api.tasks.JavaExec.html[usual configuration options] for executing
|
||||
a Java process in Gradle are available to you. The task is automatically configured to use
|
||||
the runtime classpath of the main source set.
|
||||
|
||||
By default, the main class will be configured automatically by looking for a class with a
|
||||
`public static void main(String[])` method in directories on the task's classpath.
|
||||
|
||||
The main class can also be configured explicity using the task's `main` property:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/running/boot-run-main.gradle[tags=main]
|
||||
----
|
||||
|
||||
Alternatively, if the {application-plugin}[`application` plugin] has been applied
|
||||
its `mainClassName` project property can be used:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/running/application-plugin-main-class-name.gradle[tags=main-class]
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[running-your-application-reloading-resources]]
|
||||
=== Reloading resources
|
||||
If devtools has been added to your project it will automatically monitor your
|
||||
application for changes. Alternatively, you can configure `bootRun` such that your
|
||||
application's static resources are loaded from their source location:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::../gradle/running/boot-run-source-resources.gradle[tags=source-resources]
|
||||
----
|
||||
|
||||
This makes them reloadable in the live application which can be helpful at development
|
||||
time.
|
||||
@@ -0,0 +1,11 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url 'https://repo.spring.io/libs-milestone' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'org.springframework.boot:spring-boot-gradle-plugin:{version}'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
@@ -0,0 +1,3 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '{version}'
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url 'https://repo.spring.io/libs-snapshot' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
@@ -0,0 +1,17 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
// tag::apply[]
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
// end::apply[]
|
||||
|
||||
task verify {
|
||||
doLast {
|
||||
plugins.getPlugin(org.gradle.api.plugins.JavaPlugin.class)
|
||||
plugins.getPlugin(io.spring.gradle.dependencymanagement.DependencyManagementPlugin.class)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
// tag::additional[]
|
||||
springBoot {
|
||||
buildInfo {
|
||||
properties {
|
||||
additional = [
|
||||
'a': 'alpha',
|
||||
'b': 'bravo'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
// end::additional[]
|
||||
@@ -0,0 +1,14 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
// tag::build-info[]
|
||||
springBoot {
|
||||
buildInfo()
|
||||
}
|
||||
// end::build-info[]
|
||||
@@ -0,0 +1,21 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
// tag::custom-values[]
|
||||
springBoot {
|
||||
buildInfo {
|
||||
properties {
|
||||
artifact = 'example-app'
|
||||
version = '1.2.3'
|
||||
group = 'com.example'
|
||||
name = 'Example application'
|
||||
}
|
||||
}
|
||||
}
|
||||
// end::custom-values[]
|
||||
@@ -0,0 +1,32 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
dependencyManagement {
|
||||
resolutionStrategy {
|
||||
eachDependency {
|
||||
if (it.requested.group == 'org.springframework.boot') {
|
||||
it.useVersion project.bootVersion
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tag::custom-version[]
|
||||
ext['slf4j.version'] = '1.7.20'
|
||||
// end::custom-version[]
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
task slf4jVersion {
|
||||
doLast {
|
||||
println dependencyManagement.managedVersions['org.slf4j:slf4j-api']
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
// tag::dependencies[]
|
||||
dependencies {
|
||||
compile 'org.springframework.boot:spring-boot-starter-web'
|
||||
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
}
|
||||
// end::dependencies[]
|
||||
@@ -0,0 +1,13 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'application'
|
||||
|
||||
// tag::main-class[]
|
||||
mainClassName = 'com.example.ExampleApplication'
|
||||
// end::main-class[]
|
||||
@@ -0,0 +1,21 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
bootJar {
|
||||
mainClass 'com.example.ExampleApplication'
|
||||
}
|
||||
|
||||
// tag::custom-launch-script[]
|
||||
bootJar {
|
||||
launchScript {
|
||||
included = true
|
||||
script = file('src/custom.script')
|
||||
}
|
||||
}
|
||||
// end::custom-launch-script[]
|
||||
@@ -0,0 +1,20 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
bootJar {
|
||||
mainClass 'com.example.ExampleApplication'
|
||||
}
|
||||
|
||||
// tag::include-launch-script[]
|
||||
bootJar {
|
||||
launchScript {
|
||||
included = true
|
||||
}
|
||||
}
|
||||
// end::include-launch-script[]
|
||||
@@ -0,0 +1,21 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
bootJar {
|
||||
mainClass 'com.example.ExampleApplication'
|
||||
}
|
||||
|
||||
// tag::launch-script-properties[]
|
||||
bootJar {
|
||||
launchScript {
|
||||
included = true
|
||||
properties 'logFilename': 'example-app.log'
|
||||
}
|
||||
}
|
||||
// end::launch-script-properties[]
|
||||
@@ -0,0 +1,14 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
// tag::main-class[]
|
||||
bootJar {
|
||||
mainClass = 'com.example.ExampleApplication'
|
||||
}
|
||||
// end::main-class[]
|
||||
@@ -0,0 +1,16 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
// tag::main-class[]
|
||||
bootJar {
|
||||
manifest {
|
||||
attributes 'Start-Class': 'com.example.ExampleApplication'
|
||||
}
|
||||
}
|
||||
// end::main-class[]
|
||||
@@ -0,0 +1,26 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
runtime 'org.jruby:jruby-complete:1.7.25'
|
||||
}
|
||||
|
||||
bootJar {
|
||||
mainClass 'com.example.ExampleApplication'
|
||||
}
|
||||
|
||||
// tag::requires-unpack[]
|
||||
bootJar {
|
||||
requiresUnpack '**/jruby-complete-*.jar'
|
||||
}
|
||||
// end::requires-unpack[]
|
||||
@@ -0,0 +1,19 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'war'
|
||||
|
||||
bootWar {
|
||||
mainClass 'com.example.ExampleApplication'
|
||||
classpath file('spring-boot-devtools-1.2.3.RELEASE.jar')
|
||||
}
|
||||
|
||||
// tag::include-devtools[]
|
||||
bootWar {
|
||||
excludeDevtools = false
|
||||
}
|
||||
// end::include-devtools[]
|
||||
@@ -0,0 +1,20 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'war'
|
||||
|
||||
bootWar {
|
||||
mainClass 'com.example.ExampleApplication'
|
||||
}
|
||||
|
||||
// tag::properties-launcher[]
|
||||
bootWar {
|
||||
manifest {
|
||||
attributes 'Main-Class': 'org.springframework.boot.loader.PropertiesLauncher'
|
||||
}
|
||||
}
|
||||
// end::properties-launcher[]
|
||||
@@ -0,0 +1,19 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'war'
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
// tag::dependencies[]
|
||||
dependencies {
|
||||
compile 'org.springframework.boot:spring-boot-starter-web'
|
||||
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
|
||||
}
|
||||
// end::dependencies[]
|
||||
@@ -0,0 +1,31 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
// tag::publishing[]
|
||||
publishing {
|
||||
publications {
|
||||
bootJava(MavenPublication) {
|
||||
from components.bootJava
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://repo.example.com'
|
||||
}
|
||||
}
|
||||
}
|
||||
// end::publishing[]
|
||||
|
||||
task publishingConfiguration {
|
||||
doLast {
|
||||
println publishing.publications.bootJava
|
||||
println publishing.repositories.maven.url
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath files(pluginClasspath.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
|
||||
// tag::upload[]
|
||||
uploadBootArchives {
|
||||
repositories {
|
||||
mavenDeployer {
|
||||
repository url: 'https://repo.example.com'
|
||||
}
|
||||
}
|
||||
}
|
||||
// end::upload[]
|
||||
|
||||
task deployerRepository {
|
||||
doLast {
|
||||
println uploadBootArchives.repositories.mavenDeployer.repository.url
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user