17
17
import org .apache .maven .artifact .resolver .ArtifactResolutionResult ;
18
18
import org .apache .maven .artifact .resolver .filter .ExclusionSetFilter ;
19
19
import org .apache .maven .model .Dependency ;
20
+ import org .apache .maven .plugin .logging .Log ;
21
+ import org .apache .maven .plugin .logging .SystemStreamLog ;
20
22
import org .apache .maven .project .MavenProject ;
21
23
import org .apache .maven .project .artifact .InvalidDependencyVersionException ;
22
24
import org .apache .maven .project .artifact .MavenMetadataSource ;
@@ -40,6 +42,7 @@ public static Collection<Artifact> resolveTransitively(
40
42
artifactFactory , artifactResolver ,
41
43
localRepository , artifactMetadataSource ,
42
44
dependencies , project ,
45
+ new SystemStreamLog (),
43
46
null );
44
47
}
45
48
@@ -49,10 +52,11 @@ public static Collection<Artifact> resolveTransitively(
49
52
final ArtifactRepository localRepository ,
50
53
final ArtifactMetadataSource artifactMetadataSource ,
51
54
final Dependency [] dependencies , final MavenProject project ,
55
+ final Log log ,
52
56
final String [] artifactExcludes )
53
57
throws InvalidDependencyVersionException ,
54
58
ArtifactResolutionException , ArtifactNotFoundException {
55
- if (dependencies == null ) {
59
+ if (dependencies == null || dependencies . length == 0 ) {
56
60
return Collections .emptyList ();
57
61
}
58
62
@@ -74,9 +78,18 @@ public static Collection<Artifact> resolveTransitively(
74
78
75
79
final ArtifactResolutionResult artifactResolutionResult = artifactResolver .resolve (request );
76
80
77
- final Set <Artifact > resolvedArtifacts = artifactResolutionResult .getArtifacts ();
78
-
79
- return resolvedArtifacts ;
81
+ if (!artifactResolutionResult .isSuccess ()) {
82
+ if (artifactResolutionResult .hasMissingArtifacts ()) {
83
+ log .error ("artifactResolutionResult has missing artifacts : " + artifactResolutionResult .getMissingArtifacts ());
84
+ throw new RuntimeException ("Artifacts - missing artifacts" );
85
+ } else if (artifactResolutionResult .hasExceptions ()) {
86
+ log .error ("artifactResolutionResult has exceptions : " + artifactResolutionResult .getExceptions ());
87
+ throw new RuntimeException ("Artifacts - exceptions" , artifactResolutionResult .getExceptions ().get (0 ));
88
+ } else {
89
+ log .error ("artifactResolutionResult status is not success" );
90
+ } throw new RuntimeException ("Artifacts - not in success" );
91
+ }
92
+ return artifactResolutionResult .getArtifacts ();
80
93
}
81
94
82
95
public static Collection <Artifact > resolve (
@@ -87,7 +100,7 @@ public static Collection<Artifact> resolve(
87
100
final Dependency [] dependencies , final MavenProject project )
88
101
throws InvalidDependencyVersionException ,
89
102
ArtifactResolutionException , ArtifactNotFoundException {
90
- if (dependencies == null ) {
103
+ if (dependencies == null || dependencies . length == 0 ) {
91
104
return Collections .emptyList ();
92
105
}
93
106
0 commit comments