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
201ea133
Commit
201ea133
authored
Mar 29, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Guide users to apply dependency management plugin when resolution fails
parent
8d55801c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
140 additions
and
10 deletions
+140
-10
SpringBootPlugin.java
.../springframework/boot/gradle/plugin/SpringBootPlugin.java
+8
-0
UnresolvedDependenciesAnalyzer.java
...rk/boot/gradle/plugin/UnresolvedDependenciesAnalyzer.java
+69
-0
DependencyManagementPluginActionIntegrationTests.java
...gin/DependencyManagementPluginActionIntegrationTests.java
+24
-0
GradleBuild.java
.../org/springframework/boot/gradle/testkit/GradleBuild.java
+23
-10
DependencyManagementPluginActionIntegrationTests-helpfulErrorWhenVersionlessDependencyFailsToResolve.gradle
...elpfulErrorWhenVersionlessDependencyFailsToResolve.gradle
+16
-0
No files found.
spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootPlugin.java
View file @
201ea133
...
...
@@ -78,6 +78,14 @@ public class SpringBootPlugin implements Plugin<Project> {
project
.
getPlugins
().
withType
(
action
.
getPluginClass
(),
plugin
->
action
.
execute
(
project
));
}
UnresolvedDependenciesAnalyzer
unresolvedDependenciesAnalyzer
=
new
UnresolvedDependenciesAnalyzer
();
project
.
getConfigurations
().
all
(
configuration
->
configuration
.
getIncoming
()
.
afterResolve
(
resolvableDependencies
->
unresolvedDependenciesAnalyzer
.
analyze
(
configuration
.
getResolvedConfiguration
()
.
getLenientConfiguration
()
.
getUnresolvedModuleDependencies
())));
project
.
getGradle
().
buildFinished
(
buildResult
->
unresolvedDependenciesAnalyzer
.
buildFinished
(
project
));
}
}
spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/UnresolvedDependenciesAnalyzer.java
0 → 100644
View file @
201ea133
/*
* 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
.
plugin
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
io.spring.gradle.dependencymanagement.DependencyManagementPlugin
;
import
org.gradle.api.Project
;
import
org.gradle.api.artifacts.ModuleVersionSelector
;
import
org.gradle.api.artifacts.UnresolvedDependency
;
import
org.slf4j.LoggerFactory
;
/**
* An analyzer for {@link UnresolvedDependency unresolvable dependencies} that logs a
* warning suggesting that the {@code io.spring.dependency-management} plugin is applied
* when one or more versionless dependencies fails to resolve.
*
* @author Andy Wilkinson
*/
class
UnresolvedDependenciesAnalyzer
{
private
static
final
org
.
slf4j
.
Logger
logger
=
LoggerFactory
.
getLogger
(
SpringBootPlugin
.
class
);
private
Set
<
ModuleVersionSelector
>
dependenciesWithNoVersion
=
new
HashSet
<>();
public
void
analyze
(
Set
<
UnresolvedDependency
>
unresolvedDependencies
)
{
this
.
dependenciesWithNoVersion
=
unresolvedDependencies
.
stream
()
.
map
(
unresolvedDependency
->
unresolvedDependency
.
getSelector
())
.
filter
(
this
::
hasNoVersion
).
collect
(
Collectors
.
toSet
());
}
void
buildFinished
(
Project
project
)
{
if
(!
this
.
dependenciesWithNoVersion
.
isEmpty
()
&&
!
project
.
getPlugins
().
hasPlugin
(
DependencyManagementPlugin
.
class
))
{
StringBuilder
message
=
new
StringBuilder
();
message
.
append
(
"\nDuring the build, one or more dependencies that were "
+
"declared without a version failed to resolve:\n"
);
this
.
dependenciesWithNoVersion
.
stream
()
.
forEach
(
dependency
->
message
.
append
(
" "
+
dependency
+
"\n"
));
message
.
append
(
"\nDid you forget to apply the "
+
"io.spring.dependency-management plugin to the "
+
project
.
getName
()
+
" project?\n"
);
logger
.
warn
(
message
.
toString
());
}
}
private
boolean
hasNoVersion
(
ModuleVersionSelector
selector
)
{
String
version
=
selector
.
getVersion
();
return
version
==
null
||
version
.
trim
().
length
()
==
0
;
}
}
spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests.java
View file @
201ea133
...
...
@@ -16,11 +16,16 @@
package
org
.
springframework
.
boot
.
gradle
.
plugin
;
import
java.io.File
;
import
java.io.IOException
;
import
org.gradle.testkit.runner.BuildResult
;
import
org.gradle.testkit.runner.TaskOutcome
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.springframework.boot.gradle.testkit.GradleBuild
;
import
org.springframework.util.FileSystemUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -50,4 +55,23 @@ public class DependencyManagementPluginActionIntegrationTests {
.
isEqualTo
(
TaskOutcome
.
SUCCESS
);
}
@Test
public
void
helpfulErrorWhenVersionlessDependencyFailsToResolve
()
throws
IOException
{
File
examplePackage
=
new
File
(
this
.
gradleBuild
.
getProjectDir
(),
"src/main/java/com/example"
);
examplePackage
.
mkdirs
();
FileSystemUtils
.
copyRecursively
(
new
File
(
"src/test/java/com/example"
),
examplePackage
);
BuildResult
result
=
this
.
gradleBuild
.
buildAndFail
(
"compileJava"
);
assertThat
(
result
.
task
(
":compileJava"
).
getOutcome
())
.
isEqualTo
(
TaskOutcome
.
FAILED
);
String
output
=
result
.
getOutput
();
assertThat
(
output
).
contains
(
"During the build, one or more dependencies that "
+
"were declared without a version failed to resolve:"
);
assertThat
(
output
).
contains
(
"org.springframework.boot:spring-boot-starter-web:"
);
assertThat
(
output
).
contains
(
"Did you forget to apply the "
+
"io.spring.dependency-management plugin to the "
+
this
.
gradleBuild
.
getProjectDir
().
getName
()
+
" project?"
);
}
}
spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java
View file @
201ea133
...
...
@@ -126,22 +126,35 @@ public class GradleBuild implements TestRule {
public
BuildResult
build
(
String
...
arguments
)
{
try
{
Files
.
copy
(
new
File
(
this
.
script
).
toPath
(),
new
File
(
this
.
projectDir
,
"build.gradle"
).
toPath
(),
StandardCopyOption
.
REPLACE_EXISTING
);
GradleRunner
gradleRunner
=
GradleRunner
.
create
()
.
withProjectDir
(
this
.
projectDir
).
forwardOutput
();
List
<
String
>
allArguments
=
new
ArrayList
<
String
>();
allArguments
.
add
(
"-PpluginClasspath="
+
pluginClasspath
());
allArguments
.
add
(
"-PbootVersion="
+
getBootVersion
());
allArguments
.
addAll
(
Arrays
.
asList
(
arguments
));
return
gradleRunner
.
withArguments
(
allArguments
).
build
();
return
prepareRunner
(
arguments
).
build
();
}
catch
(
Exception
ex
)
{
throw
new
RuntimeException
(
ex
);
}
}
public
BuildResult
buildAndFail
(
String
...
arguments
)
{
try
{
return
prepareRunner
(
arguments
).
buildAndFail
();
}
catch
(
Exception
ex
)
{
throw
new
RuntimeException
(
ex
);
}
}
public
GradleRunner
prepareRunner
(
String
...
arguments
)
throws
IOException
{
Files
.
copy
(
new
File
(
this
.
script
).
toPath
(),
new
File
(
this
.
projectDir
,
"build.gradle"
).
toPath
(),
StandardCopyOption
.
REPLACE_EXISTING
);
GradleRunner
gradleRunner
=
GradleRunner
.
create
().
withProjectDir
(
this
.
projectDir
)
.
forwardOutput
();
List
<
String
>
allArguments
=
new
ArrayList
<
String
>();
allArguments
.
add
(
"-PpluginClasspath="
+
pluginClasspath
());
allArguments
.
add
(
"-PbootVersion="
+
getBootVersion
());
allArguments
.
addAll
(
Arrays
.
asList
(
arguments
));
return
gradleRunner
.
withArguments
(
allArguments
);
}
public
File
getProjectDir
()
{
return
this
.
projectDir
;
}
...
...
spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests-helpfulErrorWhenVersionlessDependencyFailsToResolve.gradle
0 → 100644
View file @
201ea133
buildscript
{
dependencies
{
classpath
files
(
pluginClasspath
.
split
(
','
))
}
}
apply
plugin:
'java'
apply
plugin:
'org.springframework.boot'
repositories
{
mavenLocal
()
}
dependencies
{
compile
'org.springframework.boot:spring-boot-starter-web'
}
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