Skip to content

Commit 4b81159

Browse files
authored
Merge pull request #532 from TheSnoozer/issues-531
#531: session.getProjectDependencyGraph() might be `null` when running the plugin from eclipse
2 parents 8702f53 + 1291c70 commit 4b81159

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

maven/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,25 @@ public class GitCommitIdMojo extends AbstractMojo {
6868
/**
6969
* The list of projects in the reactor.
7070
*/
71-
@Parameter(defaultValue = "${reactorProjects}", readonly = true)
71+
@Parameter(defaultValue = "${reactorProjects}", readonly = true, required = true)
7272
List<MavenProject> reactorProjects;
7373

7474
/**
7575
* The Mojo Execution
7676
*/
77-
@Parameter(defaultValue = "${mojoExecution}", readonly = true)
77+
@Parameter(defaultValue = "${mojoExecution}", readonly = true, required = true)
7878
MojoExecution mojoExecution;
7979

8080
/**
8181
* The Maven Session Object.
8282
*/
83-
@Parameter(property = "session", required = true, readonly = true)
83+
@Parameter(defaultValue = "${session}", readonly = true, required = true)
8484
MavenSession session;
8585

8686
/**
8787
* The Maven settings.
8888
*/
89-
@Parameter(property = "settings", required = true, readonly = true)
89+
@Parameter(defaultValue = "${settings}", readonly = true, required = true)
9090
Settings settings;
9191

9292
/**
@@ -438,7 +438,13 @@ public void execute() throws MojoExecutionException {
438438
}
439439

440440
if (runOnlyOnce) {
441-
List<MavenProject> sortedProjects = session.getProjectDependencyGraph().getSortedProjects();
441+
List<MavenProject> sortedProjects =
442+
Optional.ofNullable(session.getProjectDependencyGraph())
443+
.map(graph -> graph.getSortedProjects())
444+
.orElseGet(() -> {
445+
log.warn("Maven's dependency graph is null. Assuming project is the only one executed.");
446+
return Collections.singletonList(session.getCurrentProject());
447+
});
442448
MavenProject firstProject = sortedProjects.stream()
443449
// skipPoms == true => find first project that is not pom project
444450
.filter(p -> {

0 commit comments

Comments
 (0)