@@ -113,7 +113,7 @@ public class JcpTask extends DefaultTask {
113113 /**
114114 * List of variables to be registered in preprocessor as global ones.
115115 */
116- private final MapProperty <String , String > vars ;
116+ private final MapProperty <String , Object > vars ;
117117 /**
118118 * List of patterns of folder paths to be excluded from preprocessing, It uses
119119 * ANT path pattern format.
@@ -174,7 +174,7 @@ public JcpTask(final ObjectFactory factory) {
174174 this .sourceEncoding = factory .property (String .class ).convention (StandardCharsets .UTF_8 .name ());
175175 this .eol = factory .property (String .class ).convention (System .lineSeparator ());
176176
177- this .vars = factory .mapProperty (String .class , String .class );
177+ this .vars = factory .mapProperty (String .class , Object .class );
178178
179179 this .sources = factory .listProperty (File .class );
180180 this .configFiles = factory .listProperty (String .class );
@@ -289,7 +289,7 @@ public Property<Object> getKeepComments() {
289289 }
290290
291291 @ Input
292- public MapProperty <String , String > getVars () {
292+ public MapProperty <String , Object > getVars () {
293293 return vars ;
294294 }
295295
@@ -415,10 +415,29 @@ public void warning(final String message) {
415415 preprocessorContext .setUnknownVariableAsFalse (this .unknownVarAsFalse .get ());
416416 preprocessorContext .setVerbose (this .verbose .get ());
417417
418- this .vars .getOrElse (emptyMap ()).forEach ((key , value ) -> {
419- logger .debug (String .format ("Registering global variable: %s=%s" , key , value ));
420- preprocessorContext .setGlobalVariable (key , Value .recognizeRawString (value ));
421- });
418+ this .vars .getOrElse (emptyMap ()).entrySet ().stream ()
419+ .filter (e -> {
420+ if (e .getValue () == null ) {
421+ if (this .unknownVarAsFalse .get ()) {
422+ logger .warn (String .format (
423+ "Global var '%s' ignored for null value (may be its content is empty in POM)" ,
424+ e .getKey ()));
425+ return false ;
426+ } else {
427+ throw new IllegalStateException (String .format (
428+ "Global var '%s' has null value, to ignore it set flag unknownVarAsFalse" ,
429+ e .getKey ()));
430+ }
431+ } else {
432+ return true ;
433+ }
434+ })
435+ .forEach (e -> {
436+ logger .debug (
437+ String .format ("Registering global variable: %s=%s" , e .getKey (), e .getValue ()));
438+ preprocessorContext .setGlobalVariable (e .getKey (),
439+ Value .recognizeRawString (String .valueOf (e .getValue ())));
440+ });
422441
423442 final JcpPreprocessor preprocessor = new JcpPreprocessor (preprocessorContext );
424443
0 commit comments