Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
2668e41d
Commit
2668e41d
authored
Jan 17, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it easier to just use Boot’s dependency management with Gradle
Closes gh-11059
parent
3cf1fb67
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
227 additions
and
46 deletions
+227
-46
managing-dependencies.adoc
...radle-plugin/src/main/asciidoc/managing-dependencies.adoc
+42
-0
apply-plugin-snapshot.gradle
.../main/gradle/getting-started/apply-plugin-snapshot.gradle
+1
-1
configure-bom.gradle
...rc/main/gradle/managing-dependencies/configure-bom.gradle
+35
-0
depend-on-plugin-milestone.gradle
...e/managing-dependencies/depend-on-plugin-milestone.gradle
+9
-0
depend-on-plugin-release.gradle
...dle/managing-dependencies/depend-on-plugin-release.gradle
+3
-0
depend-on-plugin-snapshot.gradle
...le/managing-dependencies/depend-on-plugin-snapshot.gradle
+9
-0
DependencyManagementPluginAction.java
.../boot/gradle/plugin/DependencyManagementPluginAction.java
+3
-43
SpringBootPlugin.java
.../springframework/boot/gradle/plugin/SpringBootPlugin.java
+45
-1
ManagingDependenciesDocumentationTests.java
...t/gradle/docs/ManagingDependenciesDocumentationTests.java
+9
-1
OnlyDependencyManagementIntegrationTests.java
...adle/plugin/OnlyDependencyManagementIntegrationTests.java
+46
-0
OnlyDependencyManagementIntegrationTests.gradle
...le/plugin/OnlyDependencyManagementIntegrationTests.gradle
+25
-0
No files found.
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/managing-dependencies.adoc
View file @
2668e41d
...
...
@@ -39,6 +39,48 @@ be done with care.
[[managing-dependencies-using-in-isolation]]
=== Using Spring Boot's dependency management in isolation
Spring Boot's dependency management can be used in a project without applying Spring
Boot's plugin to that project. The `SpringBootPlugin` class provides a `BOM_COORDINATES`
constant that can be used to import the bom without having to know its group ID,
artifact ID, or version.
First, configure the project to depend on the Spring Boot plugin but do not apply it:
ifeval::["{version-type}" == "RELEASE"]
----
include::../gradle/managing-dependencies/depend-on-plugin-release.gradle[]
----
endif::[]
ifeval::["{version-type}" == "MILESTONE"]
[source,groovy,indent=0,subs="verbatim,attributes"]
----
include::../gradle/managing-dependencies/depend-on-plugin-milestone.gradle[]
----
endif::[]
ifeval::["{version-type}" == "SNAPSHOT"]
[source,groovy,indent=0,subs="verbatim,attributes"]
----
include::../gradle/managing-dependencies/depend-on-plugin-snapshot.gradle[]
----
endif::[]
The Spring Boot plugin's dependency on the dependency management plugin means that you
can use the dependency management plugin without having to declare a dependency on it.
This also means that you will automatically use the same version of the dependency
management plugin as Spring Boot uses.
Apply the dependency management plugin and then configure it to import Spring Boot's bom:
[source,groovy,indent=0,subs="verbatim,attributes"]
----
include::../gradle/managing-dependencies/configure-bom.gradle[tags=configure-bom]
----
[[managing-dependencies-learning-more]]
=== Learning more
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/getting-started/apply-plugin-snapshot.gradle
View file @
2668e41d
...
...
@@ -4,7 +4,7 @@ buildscript {
}
dependencies
{
classpath
files
(
pluginClasspath
.
split
(
','
))
classpath
'org.springframework.boot:spring-boot-gradle-plugin:{version}'
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/configure-bom.gradle
0 → 100644
View file @
2668e41d
buildscript
{
dependencies
{
classpath
files
(
pluginClasspath
.
split
(
','
))
}
}
plugins
{
id
'java'
}
apply
plugin:
'io.spring.dependency-management'
dependencyManagement
{
resolutionStrategy
{
eachDependency
{
if
(
it
.
requested
.
group
==
'org.springframework.boot'
)
{
it
.
useVersion
project
.
bootVersion
}
}
}
}
repositories
{
mavenLocal
()
}
// tag::configure-bom[]
apply
plugin:
'io.spring.dependency-management'
dependencyManagement
{
imports
{
mavenBom
org
.
springframework
.
boot
.
gradle
.
plugin
.
SpringBootPlugin
.
BOM_COORDINATES
}
}
// end::configure-bom[]
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/depend-on-plugin-milestone.gradle
0 → 100644
View file @
2668e41d
buildscript
{
repositories
{
maven
{
url
'https://repo.spring.io/libs-milestone'
}
}
dependencies
{
classpath
'org.springframework.boot:spring-boot-gradle-plugin:{version}'
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/depend-on-plugin-release.gradle
0 → 100644
View file @
2668e41d
plugins
{
id
'org.springframework.boot'
version
'{version}'
apply
false
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/depend-on-plugin-snapshot.gradle
0 → 100644
View file @
2668e41d
buildscript
{
repositories
{
maven
{
url
'https://repo.spring.io/libs-snapshot'
}
}
dependencies
{
classpath
'org.springframework.boot:spring-boot-gradle-plugin:{version}'
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/DependencyManagementPluginAction.java
View file @
2668e41d
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -16,14 +16,6 @@
package
org
.
springframework
.
boot
.
gradle
.
plugin
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.JarURLConnection
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.util.jar.Attributes
;
import
java.util.jar.JarFile
;
import
io.spring.gradle.dependencymanagement.DependencyManagementPlugin
;
import
io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
;
import
org.gradle.api.Action
;
...
...
@@ -38,15 +30,11 @@ import org.gradle.api.Project;
*/
final
class
DependencyManagementPluginAction
implements
PluginApplicationAction
{
private
static
final
String
SPRING_BOOT_VERSION
=
determineSpringBootVersion
();
private
static
final
String
SPRING_BOOT_BOM
=
"org.springframework.boot:spring-boot-dependencies:"
+
SPRING_BOOT_VERSION
;
@Override
public
void
execute
(
Project
project
)
{
project
.
getExtensions
().
findByType
(
DependencyManagementExtension
.
class
)
.
imports
((
importsHandler
)
->
importsHandler
.
mavenBom
(
SPRING_BOOT_BOM
));
.
imports
((
importsHandler
)
->
importsHandler
.
mavenBom
(
SpringBootPlugin
.
BOM_COORDINATES
));
}
@Override
...
...
@@ -54,32 +42,4 @@ final class DependencyManagementPluginAction implements PluginApplicationAction
return
DependencyManagementPlugin
.
class
;
}
private
static
String
determineSpringBootVersion
()
{
String
implementationVersion
=
DependencyManagementPluginAction
.
class
.
getPackage
()
.
getImplementationVersion
();
if
(
implementationVersion
!=
null
)
{
return
implementationVersion
;
}
URL
codeSourceLocation
=
DependencyManagementPluginAction
.
class
.
getProtectionDomain
().
getCodeSource
().
getLocation
();
try
{
URLConnection
connection
=
codeSourceLocation
.
openConnection
();
if
(
connection
instanceof
JarURLConnection
)
{
return
getImplementationVersion
(
((
JarURLConnection
)
connection
).
getJarFile
());
}
try
(
JarFile
jarFile
=
new
JarFile
(
new
File
(
codeSourceLocation
.
toURI
())))
{
return
getImplementationVersion
(
jarFile
);
}
}
catch
(
Exception
ex
)
{
return
null
;
}
}
private
static
String
getImplementationVersion
(
JarFile
jarFile
)
throws
IOException
{
return
jarFile
.
getManifest
().
getMainAttributes
()
.
getValue
(
Attributes
.
Name
.
IMPLEMENTATION_VERSION
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootPlugin.java
View file @
2668e41d
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -16,8 +16,15 @@
package
org
.
springframework
.
boot
.
gradle
.
plugin
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.JarURLConnection
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.jar.Attributes
;
import
java.util.jar.JarFile
;
import
org.gradle.api.GradleException
;
import
org.gradle.api.Plugin
;
...
...
@@ -38,6 +45,8 @@ import org.springframework.boot.gradle.tasks.bundling.BootWar;
*/
public
class
SpringBootPlugin
implements
Plugin
<
Project
>
{
private
static
final
String
SPRING_BOOT_VERSION
=
determineSpringBootVersion
();
/**
* The name of the {@link Configuration} that contains Spring Boot archives.
* @since 2.0.0
...
...
@@ -58,6 +67,13 @@ public class SpringBootPlugin implements Plugin<Project> {
*/
public
static
final
String
BOOT_WAR_TASK_NAME
=
"bootWar"
;
/**
* The coordinates {@code (group:name:version)} of the
* {@code spring-boot-dependencies} bom.
*/
public
static
final
String
BOM_COORDINATES
=
"org.springframework.boot:spring-boot-dependencies:"
+
SPRING_BOOT_VERSION
;
@Override
public
void
apply
(
Project
project
)
{
verifyGradleVersion
();
...
...
@@ -110,4 +126,32 @@ public class SpringBootPlugin implements Plugin<Project> {
(
buildResult
)
->
unresolvedDependenciesAnalyzer
.
buildFinished
(
project
));
}
private
static
String
determineSpringBootVersion
()
{
String
implementationVersion
=
DependencyManagementPluginAction
.
class
.
getPackage
()
.
getImplementationVersion
();
if
(
implementationVersion
!=
null
)
{
return
implementationVersion
;
}
URL
codeSourceLocation
=
DependencyManagementPluginAction
.
class
.
getProtectionDomain
().
getCodeSource
().
getLocation
();
try
{
URLConnection
connection
=
codeSourceLocation
.
openConnection
();
if
(
connection
instanceof
JarURLConnection
)
{
return
getImplementationVersion
(
((
JarURLConnection
)
connection
).
getJarFile
());
}
try
(
JarFile
jarFile
=
new
JarFile
(
new
File
(
codeSourceLocation
.
toURI
())))
{
return
getImplementationVersion
(
jarFile
);
}
}
catch
(
Exception
ex
)
{
return
null
;
}
}
private
static
String
getImplementationVersion
(
JarFile
jarFile
)
throws
IOException
{
return
jarFile
.
getManifest
().
getMainAttributes
()
.
getValue
(
Attributes
.
Name
.
IMPLEMENTATION_VERSION
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/ManagingDependenciesDocumentationTests.java
View file @
2668e41d
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -47,4 +47,12 @@ public class ManagingDependenciesDocumentationTests {
.
build
(
"slf4jVersion"
).
getOutput
()).
contains
(
"1.7.20"
);
}
@Test
public
void
dependencyManagementInIsolation
()
{
assertThat
(
this
.
gradleBuild
.
script
(
"src/main/gradle/managing-dependencies/configure-bom.gradle"
)
.
build
(
"dependencyManagement"
).
getOutput
())
.
contains
(
"org.springframework.boot:spring-boot-starter "
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/OnlyDependencyManagementIntegrationTests.java
0 → 100644
View file @
2668e41d
/*
* Copyright 2012-2018 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
.
plugin
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.gradle.junit.GradleCompatibilitySuite
;
import
org.springframework.boot.gradle.testkit.GradleBuild
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for configuring a project to only use Spring Boot's dependency
* management.
*
* @author Andy Wilkinson
*/
@RunWith
(
GradleCompatibilitySuite
.
class
)
public
class
OnlyDependencyManagementIntegrationTests
{
@Rule
public
GradleBuild
gradleBuild
;
@Test
public
void
dependencyManagementCanBeConfiguredUsingCoordinatesConstant
()
{
assertThat
(
this
.
gradleBuild
.
build
(
"dependencyManagement"
).
getOutput
())
.
contains
(
"org.springframework.boot:spring-boot-starter "
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/OnlyDependencyManagementIntegrationTests.gradle
0 → 100644
View file @
2668e41d
buildscript
{
dependencies
{
classpath
files
(
pluginClasspath
.
split
(
','
))
}
}
apply
plugin:
'io.spring.dependency-management'
apply
plugin:
'java'
repositories
{
mavenLocal
()
}
dependencyManagement
{
resolutionStrategy
{
eachDependency
{
if
(
it
.
requested
.
group
==
'org.springframework.boot'
)
{
it
.
useVersion
project
.
bootVersion
}
}
}
imports
{
mavenBom
org
.
springframework
.
boot
.
gradle
.
plugin
.
SpringBootPlugin
.
BOM_COORDINATES
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment