Skip to content

Commit 467dfdb

Browse files
committed
Combine XML and Gradle code snippets into joint tabs
closes gh-16228.
1 parent 4dd00fe commit 467dfdb

File tree

1 file changed

+149
-139
lines changed

1 file changed

+149
-139
lines changed

docs/modules/ROOT/pages/getting-spring-security.adoc

Lines changed: 149 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ Typically, these are done to provide improved security to match modern security
1515

1616

1717
[[maven]]
18-
== Usage with Maven
18+
== Usage with Maven and Gradle
1919

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.
2221

2322
[[getting-maven-boot]]
24-
=== Spring Boot with Maven
23+
[[getting-gradle-boot]]
24+
=== Spring Boot with Maven and Gradle
2525

2626
Spring Boot provides a `spring-boot-starter-security` starter that aggregates Spring Security-related dependencies.
2727
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.
2828
Alternatively, you can manually add the starter, as the following example shows:
2929

30-
30+
[tabs]
31+
======
32+
Maven::
33+
+
3134
.pom.xml
3235
[source,xml,subs="verbatim,attributes"]
3336
----
@@ -40,9 +43,25 @@ Alternatively, you can manually add the starter, as the following example shows:
4043
</dependencies>
4144
----
4245
46+
Gradle::
47+
+
48+
.build.gradle
49+
[source,groovy]
50+
[subs="verbatim,attributes"]
51+
----
52+
dependencies {
53+
implementation "org.springframework.boot:spring-boot-starter-security"
54+
}
55+
----
56+
======
57+
4358
Since Spring Boot provides a Maven BOM to manage dependency versions, you do not need to specify a version.
44-
If you wish to override the Spring Security version, you can do so by providing a Maven property:
59+
If you wish to override the Spring Security version, you can do so by providing a Maven property or declaring it as a Gradle property, as shown below:
4560

61+
[tabs]
62+
======
63+
Maven::
64+
+
4665
.pom.xml
4766
[source,xml,subs="verbatim,attributes"]
4867
----
@@ -52,10 +71,24 @@ If you wish to override the Spring Security version, you can do so by providing
5271
</properties>
5372
----
5473
74+
Gradle::
75+
+
76+
.build.gradle
77+
[source,groovy]
78+
[subs="verbatim,attributes"]
79+
----
80+
ext['spring-security.version']='{spring-security-version}'
81+
----
82+
======
83+
5584
Since Spring Security makes breaking changes only in major releases, you can safely use a newer version of Spring Security with Spring Boot.
5685
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:
5887

88+
[tabs]
89+
======
90+
Maven::
91+
+
5992
.pom.xml
6093
[source,xml,subs="verbatim,attributes"]
6194
----
@@ -65,13 +98,27 @@ You can do so by adding a Maven property:
6598
</properties>
6699
----
67100
101+
Gradle::
102+
+
103+
.build.gradle
104+
[source,groovy]
105+
[subs="verbatim,attributes"]
106+
----
107+
ext['spring.version']='{spring-core-version}'
108+
----
109+
======
110+
68111
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].
69112

70113
[[getting-maven-no-boot]]
71-
=== Maven Without Spring Boot
114+
=== Standalone Usage (Without Spring Boot)
72115

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]:
74117

118+
[tabs]
119+
======
120+
Maven::
121+
+
75122
.pom.xml
76123
[source,xml,ubs="verbatim,attributes"]
77124
----
@@ -89,8 +136,31 @@ When you use Spring Security without Spring Boot, the preferred way is to use Sp
89136
</dependencyManagement>
90137
----
91138
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"
147+
}
148+
149+
dependencyManagement {
150+
imports {
151+
mavenBom 'org.springframework.security:spring-security-bom:{spring-security-version}'
152+
}
153+
}
154+
----
155+
======
156+
157+
92158
A minimal Spring Security Maven set of dependencies typically looks like the following example:
93159

160+
[tabs]
161+
======
162+
Maven::
163+
+
94164
.pom.xml
95165
[source,xml,subs="verbatim,attributes"]
96166
----
@@ -107,12 +177,29 @@ A minimal Spring Security Maven set of dependencies typically looks like the fol
107177
</dependencies>
108178
----
109179
180+
Gradle::
181+
+
182+
.build.gradle
183+
[source,groovy]
184+
[subs="verbatim,attributes"]
185+
----
186+
dependencies {
187+
implementation "org.springframework.security:spring-security-web"
188+
implementation "org.springframework.security:spring-security-config"
189+
}
190+
----
191+
======
192+
110193
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].
111194

112195
Spring Security builds against Spring Framework {spring-core-version} but should generally work with any newer version of Spring Framework 5.x.
113196
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]:
115198

199+
[tabs]
200+
======
201+
Maven::
202+
+
116203
.pom.xml
117204
[source,xml,subs="verbatim,attributes"]
118205
----
@@ -130,6 +217,24 @@ The easiest way to resolve this is to use the `spring-framework-bom` within the
130217
</dependencyManagement>
131218
----
132219
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"
228+
}
229+
230+
dependencyManagement {
231+
imports {
232+
mavenBom 'org.springframework:spring-framework-bom:{spring-core-version}'
233+
}
234+
}
235+
----
236+
======
237+
133238
The preceding example ensures that all the transitive dependencies of Spring Security use the Spring {spring-core-version} modules.
134239

135240
[NOTE]
@@ -138,12 +243,24 @@ This approach uses Maven's "`bill of materials`" (BOM) concept and is only avail
138243
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].
139244
====
140245

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+
----
144257

145258
If you use a SNAPSHOT version, you need to ensure that you have the Spring Snapshot repository defined:
146259

260+
[tabs]
261+
======
262+
Maven::
263+
+
147264
.pom.xml
148265
[source,xml]
149266
----
@@ -157,8 +274,23 @@ If you use a SNAPSHOT version, you need to ensure that you have the Spring Snaps
157274
</repositories>
158275
----
159276
277+
Gradle::
278+
+
279+
.build.gradle
280+
[source,groovy]
281+
----
282+
repositories {
283+
maven { url 'https://repo.spring.io/snapshot' }
284+
}
285+
----
286+
======
287+
160288
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:
161289

290+
[tabs]
291+
======
292+
Maven::
293+
+
162294
.pom.xml
163295
[source,xml]
164296
----
@@ -172,136 +304,14 @@ If you use a milestone or release candidate version, you need to ensure that you
172304
</repositories>
173305
----
174306
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.
186-
187-
Alternatively, you can manually add the starter:
188-
189-
.build.gradle
190-
[source,groovy]
191-
[subs="verbatim,attributes"]
192-
----
193-
dependencies {
194-
implementation "org.springframework.boot:spring-boot-starter-security"
195-
}
196-
----
197-
198-
Since Spring Boot provides a Maven BOM to manage dependency versions, you need not specify a version.
199-
If you wish to override the Spring Security version, you can do so by providing a Gradle property:
200-
201-
.build.gradle
202-
[source,groovy]
203-
[subs="verbatim,attributes"]
204-
----
205-
ext['spring-security.version']='{spring-security-version}'
206-
----
207-
208-
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"
232-
}
233-
234-
dependencyManagement {
235-
imports {
236-
mavenBom 'org.springframework.security:spring-security-bom:{spring-security-version}'
237-
}
238-
}
239-
----
240-
241-
A minimal Spring Security Maven set of dependencies typically looks like the following:
242-
243-
.build.gradle
244-
[source,groovy]
245-
[subs="verbatim,attributes"]
246-
----
247-
dependencies {
248-
implementation "org.springframework.security:spring-security-web"
249-
implementation "org.springframework.security:spring-security-config"
250-
}
251-
----
252-
253-
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"
266-
}
267-
268-
dependencyManagement {
269-
imports {
270-
mavenBom 'org.springframework:spring-framework-bom:{spring-core-version}'
271-
}
272-
}
273-
----
274-
275-
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:
300-
307+
Gradle::
308+
+
301309
.build.gradle
302310
[source,groovy]
303311
----
304312
repositories {
305313
maven { url 'https://repo.spring.io/milestone' }
306314
}
307315
----
316+
======
317+

0 commit comments

Comments
 (0)