Skip to content

Commit 1b97e8d

Browse files
author
Dave Syer
committed
Skip dependency exclusions if groupId is null
Fixes gh-1133
1 parent 078db8c commit 1b97e8d

File tree

3 files changed

+107
-14
lines changed

3 files changed

+107
-14
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2012-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.gradle;
18+
19+
import java.io.File;
20+
21+
import org.gradle.tooling.ProjectConnection;
22+
import org.junit.Before;
23+
import org.junit.Test;
24+
import org.springframework.boot.dependency.tools.ManagedDependencies;
25+
import org.springframework.util.FileCopyUtils;
26+
import org.springframework.util.FileSystemUtils;
27+
28+
/**
29+
* Tests for using the Gradle plugin's support for flat directory repos
30+
*
31+
* @author Dave Syer
32+
*/
33+
public class FlatdirTests {
34+
35+
private ProjectConnection project;
36+
37+
private File libs = new File("target/flatdir/lib");
38+
39+
private static final String BOOT_VERSION = ManagedDependencies.get().find(
40+
"spring-boot").getVersion();
41+
42+
@Before
43+
public void init() {
44+
if (libs.exists()) {
45+
FileSystemUtils.deleteRecursively(libs);
46+
}
47+
}
48+
49+
@Test
50+
public void flatdir() throws Exception {
51+
project = new ProjectCreator().createProject("flatdir");
52+
if (!libs.exists()) {
53+
libs.mkdirs();
54+
}
55+
FileCopyUtils.copy(new File("src/test/resources/foo.jar"),
56+
new File(libs, "foo-1.0.0.jar"));
57+
project.newBuild().forTasks("build").withArguments(
58+
"-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
59+
}
60+
61+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal()
4+
}
5+
dependencies {
6+
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
7+
}
8+
}
9+
10+
apply plugin: 'spring-boot'
11+
12+
group = 'flatdir'
13+
version = '0.0.0'
14+
15+
run {
16+
main = 'Foo'
17+
}
18+
19+
jar {
20+
baseName = 'flatdir'
21+
}
22+
23+
repositories {
24+
flatDir( dirs:'lib' )
25+
}
26+
27+
dependencies {
28+
compile ':foo:1.0.0'
29+
}

spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/exclude/ApplyExcludeRules.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ public void execute(Configuration configuration) {
4949
if (!VersionManagedDependencies.CONFIGURATION.equals(configuration.getName())) {
5050
configuration.getIncoming().beforeResolve(
5151
new Action<ResolvableDependencies>() {
52+
5253
@Override
5354
public void execute(ResolvableDependencies resolvableDependencies) {
5455
resolvableDependencies.getDependencies().all(
5556
new Action<Dependency>() {
57+
5658
@Override
5759
public void execute(Dependency dependency) {
5860
applyExcludeRules(dependency);
@@ -70,20 +72,21 @@ private void applyExcludeRules(Dependency dependency) {
7072
}
7173

7274
private void applyExcludeRules(ModuleDependency dependency) {
73-
ManagedDependencies managedDependencies = versionManagedDependencies
74-
.getManagedDependencies();
75-
org.springframework.boot.dependency.tools.Dependency managedDependency = managedDependencies
76-
.find(dependency.getGroup(), dependency.getName());
77-
if (managedDependency != null) {
78-
for (Exclusion exclusion : managedDependency.getExclusions()) {
79-
addExcludeRule(dependency, exclusion);
75+
ManagedDependencies managedDependencies = versionManagedDependencies.getManagedDependencies();
76+
// flat directory repositories do not have groups
77+
if (dependency.getGroup() != null) {
78+
org.springframework.boot.dependency.tools.Dependency managedDependency = managedDependencies.find(
79+
dependency.getGroup(), dependency.getName());
80+
if (managedDependency != null) {
81+
for (Exclusion exclusion : managedDependency.getExclusions()) {
82+
addExcludeRule(dependency, exclusion);
83+
}
84+
addImplicitExcludeRules(dependency);
85+
return;
8086
}
81-
addImplicitExcludeRules(dependency);
82-
}
83-
else {
84-
logger.debug("No exclusions rules applied for non-managed dependency "
85-
+ dependency);
8687
}
88+
logger.debug("No exclusions rules applied for non-managed dependency "
89+
+ dependency);
8790
}
8891

8992
private void addExcludeRule(ModuleDependency dependency, Exclusion exclusion) {
@@ -106,8 +109,8 @@ private void addImplicitExcludeRules(ModuleDependency dependency) {
106109

107110
private boolean isStarter(ModuleDependency dependency) {
108111
return (dependency.getGroup() != null
109-
&& dependency.getGroup().equals("org.springframework.boot") && dependency
110-
.getName().startsWith("spring-boot-starter"));
112+
&& dependency.getGroup().equals("org.springframework.boot") && dependency.getName().startsWith(
113+
"spring-boot-starter"));
111114
}
112115

113116
}

0 commit comments

Comments
 (0)