40
40
*/
41
41
@ Mojo (name = "add-test-source" , defaultPhase = LifecyclePhase .GENERATE_TEST_SOURCES , threadSafe = true )
42
42
public class AddTestSourceMojo extends AbstractMojo {
43
+
43
44
/**
44
45
* Additional test source directories.
45
46
*
@@ -62,6 +63,14 @@ public class AddTestSourceMojo extends AbstractMojo {
62
63
@ Parameter (property = "buildhelper.addtestsource.skip" , defaultValue = "false" )
63
64
private boolean skipAddTestSource ;
64
65
66
+ /**
67
+ * If a directory does not exist, do not add it as a test source root.
68
+ *
69
+ * @since 3.5.0
70
+ */
71
+ @ Parameter (property = "buildhelper.addtestsource.skipIfMissing" , defaultValue = "false" )
72
+ private boolean skipAddTestSourceIfMissing ;
73
+
65
74
public void execute () {
66
75
if (skipAddTestSource ) {
67
76
if (getLog ().isInfoEnabled ()) {
@@ -71,9 +80,15 @@ public void execute() {
71
80
}
72
81
73
82
for (File source : sources ) {
74
- this .project .addTestCompileSourceRoot (source .getAbsolutePath ());
75
- if (getLog ().isInfoEnabled ()) {
76
- getLog ().info ("Test Source directory: " + source + " added." );
83
+ if (skipAddTestSourceIfMissing && !source .exists ()) {
84
+ if (getLog ().isDebugEnabled ()) {
85
+ getLog ().debug ("Skipping directory: " + source + ", because it does not exist." );
86
+ }
87
+ } else {
88
+ this .project .addTestCompileSourceRoot (source .getAbsolutePath ());
89
+ if (getLog ().isInfoEnabled ()) {
90
+ getLog ().info ("Test Source directory: " + source + " added." );
91
+ }
77
92
}
78
93
}
79
94
}
0 commit comments