Skip to content

Commit 822bf7b

Browse files
committed
Prevent NullPointerException if no dependencies to resolve
A project that is a pom has a "null" artifact, so we have to defend against that being added to the automatic deployables. Also adds a multi-module project and a pom-only project for testing.
1 parent 0e2fbf3 commit 822bf7b

File tree

26 files changed

+1251
-7
lines changed

26 files changed

+1251
-7
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ dependency-reduced-pom.xml
1717
.project
1818
.settings
1919
.springBeans
20+
.sts4-cache/
21+
.attach_pid*
2022

2123
### IntelliJ IDEA ###
2224
.idea

maven-plugin/src/main/java/org/springframework/boot/experimental/maven/ResolveMojo.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class ResolveMojo extends ThinJarMojo {
6161
/**
6262
* Directory containing the downloaded archives.
6363
*/
64-
@Parameter(defaultValue = "${project.build.directory}/thin/root", required = true, property="thin.outputDirectory")
64+
@Parameter(defaultValue = "${project.build.directory}/thin/root", required = true, property = "thin.outputDirectory")
6565
private File outputDirectory;
6666

6767
/**
@@ -73,13 +73,13 @@ public class ResolveMojo extends ThinJarMojo {
7373
/**
7474
* A flag to indicate whether to include the current project as a deployable.
7575
*/
76-
@Parameter(property="thin.includeSelf")
76+
@Parameter(property = "thin.includeSelf")
7777
private boolean includeSelf = true;
7878

7979
/**
8080
* A flag to indicate whether to unpack the main archive (self).
8181
*/
82-
@Parameter(property="thin.unpack")
82+
@Parameter(property = "thin.unpack")
8383
private boolean unpack = false;
8484

8585
/**
@@ -100,12 +100,17 @@ public void execute() throws MojoExecutionException, MojoFailureException {
100100

101101
List<File> deployables = new ArrayList<>();
102102
File file = this.project.getArtifact().getFile();
103-
if (this.includeSelf && !this.unpack) {
103+
if (file != null && this.includeSelf && !this.unpack) {
104104
deployables.add(file);
105105
}
106106
if (this.deployables != null) {
107107
for (Dependency deployable : this.deployables) {
108-
deployables.add(resolveFile(deployable));
108+
if (deployable != null) {
109+
File resolved = resolveFile(deployable);
110+
if (resolved != null) {
111+
deployables.add(resolved);
112+
}
113+
}
109114
}
110115
}
111116

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
buildscript {
2+
ext {
3+
springBootVersion = '1.5.10.RELEASE'
4+
wrapperVersion = '1.0.10.BUILD-SNAPSHOT'
5+
}
6+
repositories {
7+
mavenLocal()
8+
mavenCentral()
9+
}
10+
dependencies {
11+
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
12+
classpath("org.springframework.boot.experimental:spring-boot-thin-gradle-plugin:${wrapperVersion}")
13+
}
14+
}
15+
16+
apply plugin: 'java'
17+
apply plugin: 'eclipse'
18+
apply plugin: 'maven'
19+
apply plugin: 'org.springframework.boot'
20+
apply plugin: 'io.spring.dependency-management'
21+
apply plugin: 'org.springframework.boot.experimental.thin-launcher'
22+
23+
jar {
24+
baseName = 'application'
25+
version = '0.0.1-SNAPSHOT'
26+
}
27+
group = 'com.example'
28+
version = '0.0.1-SNAPSHOT'
29+
sourceCompatibility = 1.8
30+
31+
repositories { mavenCentral() }
32+
33+
dependencies {
34+
compile('org.springframework.boot:spring-boot-starter-actuator')
35+
compile('org.springframework.boot:spring-boot-starter-web')
36+
compile project(':library')
37+
testCompile('org.springframework.boot:spring-boot-starter-test')
38+
}
39+

samples/multi/application/pom.xml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>application</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<parent>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-starter-parent</artifactId>
14+
<version>1.5.10.RELEASE</version>
15+
<relativePath /> <!-- lookup parent from repository -->
16+
</parent>
17+
18+
<properties>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
<java.version>1.8</java.version>
21+
<wrapper.version>1.0.10.BUILD-SNAPSHOT</wrapper.version>
22+
</properties>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-actuator</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter-web</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.example</groupId>
35+
<artifactId>library</artifactId>
36+
<version>${project.version}</version>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-test</artifactId>
42+
<scope>test</scope>
43+
</dependency>
44+
</dependencies>
45+
46+
<build>
47+
<plugins>
48+
<plugin>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-deploy-plugin</artifactId>
51+
<configuration>
52+
<skip>true</skip>
53+
</configuration>
54+
</plugin>
55+
<plugin>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-maven-plugin</artifactId>
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.springframework.boot.experimental</groupId>
61+
<artifactId>spring-boot-thin-layout</artifactId>
62+
<version>${wrapper.version}</version>
63+
</dependency>
64+
</dependencies>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
69+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package hello.app;
2+
3+
import hello.service.MyService;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
@SpringBootApplication(scanBasePackages = "hello")
10+
@RestController
11+
public class DemoApplication {
12+
13+
private final MyService myService;
14+
15+
public DemoApplication(MyService myService) {
16+
this.myService = myService;
17+
}
18+
19+
@GetMapping("/")
20+
public String home() {
21+
return myService.message();
22+
}
23+
24+
public static void main(String[] args) {
25+
SpringApplication.run(DemoApplication.class, args);
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
service.message=Hello World
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package hello.app;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.context.SpringBootTest;
9+
import org.springframework.test.context.junit4.SpringRunner;
10+
11+
import hello.service.MyService;
12+
13+
@RunWith(SpringRunner.class)
14+
@SpringBootTest
15+
public class DemoApplicationTest {
16+
17+
@Autowired
18+
private MyService myService;
19+
20+
@Test
21+
public void contextLoads() {
22+
assertThat(myService).isNotNull();
23+
}
24+
25+
}
53.4 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
zipStoreBase=GRADLE_USER_HOME
4+
zipStorePath=wrapper/dists
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip

samples/multi/gradlew

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#!/usr/bin/env sh
2+
3+
##############################################################################
4+
##
5+
## Gradle start up script for UN*X
6+
##
7+
##############################################################################
8+
9+
# Attempt to set APP_HOME
10+
# Resolve links: $0 may be a link
11+
PRG="$0"
12+
# Need this for relative symlinks.
13+
while [ -h "$PRG" ] ; do
14+
ls=`ls -ld "$PRG"`
15+
link=`expr "$ls" : '.*-> \(.*\)$'`
16+
if expr "$link" : '/.*' > /dev/null; then
17+
PRG="$link"
18+
else
19+
PRG=`dirname "$PRG"`"/$link"
20+
fi
21+
done
22+
SAVED="`pwd`"
23+
cd "`dirname \"$PRG\"`/" >/dev/null
24+
APP_HOME="`pwd -P`"
25+
cd "$SAVED" >/dev/null
26+
27+
APP_NAME="Gradle"
28+
APP_BASE_NAME=`basename "$0"`
29+
30+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31+
DEFAULT_JVM_OPTS=""
32+
33+
# Use the maximum available, or set MAX_FD != -1 to use that value.
34+
MAX_FD="maximum"
35+
36+
warn () {
37+
echo "$*"
38+
}
39+
40+
die () {
41+
echo
42+
echo "$*"
43+
echo
44+
exit 1
45+
}
46+
47+
# OS specific support (must be 'true' or 'false').
48+
cygwin=false
49+
msys=false
50+
darwin=false
51+
nonstop=false
52+
case "`uname`" in
53+
CYGWIN* )
54+
cygwin=true
55+
;;
56+
Darwin* )
57+
darwin=true
58+
;;
59+
MINGW* )
60+
msys=true
61+
;;
62+
NONSTOP* )
63+
nonstop=true
64+
;;
65+
esac
66+
67+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68+
69+
# Determine the Java command to use to start the JVM.
70+
if [ -n "$JAVA_HOME" ] ; then
71+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72+
# IBM's JDK on AIX uses strange locations for the executables
73+
JAVACMD="$JAVA_HOME/jre/sh/java"
74+
else
75+
JAVACMD="$JAVA_HOME/bin/java"
76+
fi
77+
if [ ! -x "$JAVACMD" ] ; then
78+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79+
80+
Please set the JAVA_HOME variable in your environment to match the
81+
location of your Java installation."
82+
fi
83+
else
84+
JAVACMD="java"
85+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86+
87+
Please set the JAVA_HOME variable in your environment to match the
88+
location of your Java installation."
89+
fi
90+
91+
# Increase the maximum file descriptors if we can.
92+
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93+
MAX_FD_LIMIT=`ulimit -H -n`
94+
if [ $? -eq 0 ] ; then
95+
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96+
MAX_FD="$MAX_FD_LIMIT"
97+
fi
98+
ulimit -n $MAX_FD
99+
if [ $? -ne 0 ] ; then
100+
warn "Could not set maximum file descriptor limit: $MAX_FD"
101+
fi
102+
else
103+
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104+
fi
105+
fi
106+
107+
# For Darwin, add options to specify how the application appears in the dock
108+
if $darwin; then
109+
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110+
fi
111+
112+
# For Cygwin, switch paths to Windows format before running java
113+
if $cygwin ; then
114+
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115+
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116+
JAVACMD=`cygpath --unix "$JAVACMD"`
117+
118+
# We build the pattern for arguments to be converted via cygpath
119+
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120+
SEP=""
121+
for dir in $ROOTDIRSRAW ; do
122+
ROOTDIRS="$ROOTDIRS$SEP$dir"
123+
SEP="|"
124+
done
125+
OURCYGPATTERN="(^($ROOTDIRS))"
126+
# Add a user-defined pattern to the cygpath arguments
127+
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128+
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129+
fi
130+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
131+
i=0
132+
for arg in "$@" ; do
133+
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134+
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135+
136+
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137+
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138+
else
139+
eval `echo args$i`="\"$arg\""
140+
fi
141+
i=$((i+1))
142+
done
143+
case $i in
144+
(0) set -- ;;
145+
(1) set -- "$args0" ;;
146+
(2) set -- "$args0" "$args1" ;;
147+
(3) set -- "$args0" "$args1" "$args2" ;;
148+
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149+
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150+
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151+
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152+
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153+
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154+
esac
155+
fi
156+
157+
# Escape application args
158+
save () {
159+
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160+
echo " "
161+
}
162+
APP_ARGS=$(save "$@")
163+
164+
# Collect all arguments for the java command, following the shell quoting and substitution rules
165+
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166+
167+
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168+
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169+
cd "$(dirname "$0")"
170+
fi
171+
172+
exec "$JAVACMD" "$@"

0 commit comments

Comments
 (0)