You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -15,19 +15,22 @@ Typically, these are done to provide improved security to match modern security
15
15
16
16
17
17
[[maven]]
18
-
== Usage with Maven
18
+
== Usage with Maven and Gradle
19
19
20
-
As most open source projects, Spring Security deploys its dependencies as Maven artifacts.
21
-
The topics in this section describe how to consume Spring Security when using Maven.
20
+
As most open source projects, Spring Security deploys its dependencies as Maven artifacts, which makes them compatible with both Maven and Gradle. The following sections demonstrate how to integrate Spring Security with these build tools, with examples for Spring Boot and standalone usage.
22
21
23
22
[[getting-maven-boot]]
24
-
=== Spring Boot with Maven
23
+
[[getting-gradle-boot]]
24
+
=== Spring Boot with Maven and Gradle
25
25
26
26
Spring Boot provides a `spring-boot-starter-security` starter that aggregates Spring Security-related dependencies.
27
27
The simplest and preferred way to use the starter is to use https://docs.spring.io/initializr/docs/current/reference/html/[Spring Initializr] by using an IDE integration in (https://joshlong.com/jl/blogPost/tech_tip_geting_started_with_spring_boot.html[Eclipse] or https://www.jetbrains.com/help/idea/spring-boot.html#d1489567e2[IntelliJ], https://github.com/AlexFalappa/nb-springboot/wiki/Quick-Tour[NetBeans]) or through https://start.spring.io.
28
28
Alternatively, you can manually add the starter, as the following example shows:
29
29
30
-
30
+
[tabs]
31
+
======
32
+
Maven::
33
+
+
31
34
.pom.xml
32
35
[source,xml,subs="verbatim,attributes"]
33
36
----
@@ -40,9 +43,25 @@ Alternatively, you can manually add the starter, as the following example shows:
Since Spring Security makes breaking changes only in major releases, you can safely use a newer version of Spring Security with Spring Boot.
56
85
However, at times, you may need to update the version of Spring Framework as well.
57
-
You can do so by adding a Maven property:
86
+
You can do so by adding a Maven or Gradle property:
58
87
88
+
[tabs]
89
+
======
90
+
Maven::
91
+
+
59
92
.pom.xml
60
93
[source,xml,subs="verbatim,attributes"]
61
94
----
@@ -65,13 +98,27 @@ You can do so by adding a Maven property:
65
98
</properties>
66
99
----
67
100
101
+
Gradle::
102
+
+
103
+
.build.gradle
104
+
[source,groovy]
105
+
[subs="verbatim,attributes"]
106
+
----
107
+
ext['spring.version']='{spring-core-version}'
108
+
----
109
+
======
110
+
68
111
If you use additional features (such as LDAP, OAuth 2, and others), you need to also include the appropriate xref:modules.adoc#modules[Project Modules and Dependencies].
69
112
70
113
[[getting-maven-no-boot]]
71
-
=== Maven Without Spring Boot
114
+
=== Standalone Usage (Without Spring Boot)
72
115
73
-
When you use Spring Security without Spring Boot, the preferred way is to use Spring Security's BOM to ensure that a consistent version of Spring Security is used throughout the entire project. The following example shows how to do so:
116
+
When you use Spring Security without Spring Boot, the preferred way is to use Spring Security's BOM to ensure that a consistent version of Spring Security is used throughout the entire project. For Gradle, you can do so by using the https://github.com/spring-gradle-plugins/dependency-management-plugin[Dependency Management Plugin]:
74
117
118
+
[tabs]
119
+
======
120
+
Maven::
121
+
+
75
122
.pom.xml
76
123
[source,xml,ubs="verbatim,attributes"]
77
124
----
@@ -89,8 +136,31 @@ When you use Spring Security without Spring Boot, the preferred way is to use Sp
89
136
</dependencyManagement>
90
137
----
91
138
139
+
Gradle::
140
+
+
141
+
.build.gradle
142
+
[source,groovy]
143
+
[subs="verbatim,attributes"]
144
+
----
145
+
plugins {
146
+
id "io.spring.dependency-management" version "1.0.6.RELEASE"
If you use additional features (such as LDAP, OAuth 2, and others), you need to also include the appropriate xref:modules.adoc#modules[Project Modules and Dependencies].
111
194
112
195
Spring Security builds against Spring Framework {spring-core-version} but should generally work with any newer version of Spring Framework 5.x.
113
196
Many users are likely to run afoul of the fact that Spring Security's transitive dependencies resolve Spring Framework {spring-core-version}, which can cause strange classpath problems.
114
-
The easiest way to resolve this is to use the `spring-framework-bom` within the `<dependencyManagement>` section of your `pom.xml`:
197
+
The easiest way to resolve this is to use the `spring-framework-bom` within the `<dependencyManagement>` section of your `pom.xml` or your `dependencyManagement` section of your `build.gradle`. For Gradle, you can do so by using the https://github.com/spring-gradle-plugins/dependency-management-plugin[Dependency Management Plugin]:
115
198
199
+
[tabs]
200
+
======
201
+
Maven::
202
+
+
116
203
.pom.xml
117
204
[source,xml,subs="verbatim,attributes"]
118
205
----
@@ -130,6 +217,24 @@ The easiest way to resolve this is to use the `spring-framework-bom` within the
130
217
</dependencyManagement>
131
218
----
132
219
220
+
Gradle::
221
+
+
222
+
.build.gradle
223
+
[source,groovy]
224
+
[subs="verbatim,attributes"]
225
+
----
226
+
plugins {
227
+
id "io.spring.dependency-management" version "1.0.6.RELEASE"
The preceding example ensures that all the transitive dependencies of Spring Security use the Spring {spring-core-version} modules.
134
239
135
240
[NOTE]
@@ -138,12 +243,24 @@ This approach uses Maven's "`bill of materials`" (BOM) concept and is only avail
138
243
For additional details about how dependencies are resolved, see https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html[Maven's Introduction to the Dependency Mechanism documentation].
139
244
====
140
245
141
-
[[maven-repositories]]
142
-
=== Maven Repositories
143
-
All GA releases (that is, versions ending in .RELEASE) are deployed to Maven Central, so you need not declare additional Maven repositories in your pom.
246
+
[[maven-gradle-gearepositories]]
247
+
=== Maven and Gradle Repositories
248
+
All GA releases (that is, versions ending in .RELEASE) are deployed to Maven Central, so you need not declare additional Maven repositories in your `pom.xml` or, for Gradle, using the `mavenCentral()` repository is sufficient for GA releases.
249
+
250
+
.build.gradle
251
+
[source,groovy]
252
+
----
253
+
repositories {
254
+
mavenCentral()
255
+
}
256
+
----
144
257
145
258
If you use a SNAPSHOT version, you need to ensure that you have the Spring Snapshot repository defined:
146
259
260
+
[tabs]
261
+
======
262
+
Maven::
263
+
+
147
264
.pom.xml
148
265
[source,xml]
149
266
----
@@ -157,8 +274,23 @@ If you use a SNAPSHOT version, you need to ensure that you have the Spring Snaps
157
274
</repositories>
158
275
----
159
276
277
+
Gradle::
278
+
+
279
+
.build.gradle
280
+
[source,groovy]
281
+
----
282
+
repositories {
283
+
maven { url 'https://repo.spring.io/snapshot' }
284
+
}
285
+
----
286
+
======
287
+
160
288
If you use a milestone or release candidate version, you need to ensure that you have the Spring Milestone repository defined, as the following example shows:
161
289
290
+
[tabs]
291
+
======
292
+
Maven::
293
+
+
162
294
.pom.xml
163
295
[source,xml]
164
296
----
@@ -172,136 +304,14 @@ If you use a milestone or release candidate version, you need to ensure that you
172
304
</repositories>
173
305
----
174
306
175
-
[[getting-gradle]]
176
-
== Gradle
177
-
178
-
As most open source projects, Spring Security deploys its dependencies as Maven artifacts, which allows for first-class Gradle support.
179
-
The following topics describe how to consume Spring Security when using Gradle.
180
-
181
-
[[getting-gradle-boot]]
182
-
=== Spring Boot with Gradle
183
-
184
-
Spring Boot provides a `spring-boot-starter-security` starter that aggregates Spring Security related dependencies.
185
-
The simplest and preferred method to use the starter is to use https://docs.spring.io/initializr/docs/current/reference/html/[Spring Initializr] by using an IDE integration in (https://joshlong.com/jl/blogPost/tech_tip_geting_started_with_spring_boot.html[Eclipse] or https://www.jetbrains.com/help/idea/spring-boot.html#d1489567e2[IntelliJ], https://github.com/AlexFalappa/nb-springboot/wiki/Quick-Tour[NetBeans]) or through https://start.spring.io.
Since Spring Security makes breaking changes only in major releases, you can safely use a newer version of Spring Security with Spring Boot.
209
-
However, at times, you may need to update the version of Spring Framework as well.
210
-
You can do so by adding a Gradle property:
211
-
212
-
.build.gradle
213
-
[source,groovy]
214
-
[subs="verbatim,attributes"]
215
-
----
216
-
ext['spring.version']='{spring-core-version}'
217
-
----
218
-
219
-
If you use additional features (such as LDAP, OAuth 2, and others), you need to also include the appropriate xref:modules.adoc#modules[Project Modules and Dependencies].
220
-
221
-
=== Gradle Without Spring Boot
222
-
223
-
When you use Spring Security without Spring Boot, the preferred way is to use Spring Security's BOM to ensure a consistent version of Spring Security is used throughout the entire project.
224
-
You can do so by using the https://github.com/spring-gradle-plugins/dependency-management-plugin[Dependency Management Plugin]:
225
-
226
-
.build.gradle
227
-
[source,groovy]
228
-
[subs="verbatim,attributes"]
229
-
----
230
-
plugins {
231
-
id "io.spring.dependency-management" version "1.0.6.RELEASE"
If you use additional features (such as LDAP, OAuth 2, and others), you need to also include the appropriate xref:modules.adoc#modules[Project Modules and Dependencies].
254
-
255
-
Spring Security builds against Spring Framework {spring-core-version} but should generally work with any newer version of Spring Framework 5.x.
256
-
Many users are likely to run afoul of the fact that Spring Security's transitive dependencies resolve Spring Framework {spring-core-version}, which can cause strange classpath problems.
257
-
The easiest way to resolve this is to use the `spring-framework-bom` within your `dependencyManagement` section of your `build.gradle`.
258
-
You can do so by using the https://github.com/spring-gradle-plugins/dependency-management-plugin[Dependency Management Plugin]:
259
-
260
-
.build.gradle
261
-
[source,groovy]
262
-
[subs="verbatim,attributes"]
263
-
----
264
-
plugins {
265
-
id "io.spring.dependency-management" version "1.0.6.RELEASE"
The preceding example ensures that all the transitive dependencies of Spring Security use the Spring {spring-core-version} modules.
276
-
277
-
[[gradle-repositories]]
278
-
=== Gradle Repositories
279
-
All GA releases (that is, versions ending in .RELEASE) are deployed to Maven Central, so using the `mavenCentral()` repository is sufficient for GA releases. The following example shows how to do so:
280
-
281
-
.build.gradle
282
-
[source,groovy]
283
-
----
284
-
repositories {
285
-
mavenCentral()
286
-
}
287
-
----
288
-
289
-
If you use a SNAPSHOT version, you need to ensure that you have the Spring Snapshot repository defined:
290
-
291
-
.build.gradle
292
-
[source,groovy]
293
-
----
294
-
repositories {
295
-
maven { url 'https://repo.spring.io/snapshot' }
296
-
}
297
-
----
298
-
299
-
If you use a milestone or release candidate version, you need to ensure that you have the Spring Milestone repository defined:
0 commit comments