grails/grails-core — pull request #492 by jdpgrailsdev (2014-05-06 13:57:06+00:00)
Title: JDK-based Maven profile activiation fix

When using an external POM file that contains a Maven profile that is activated based on the current JDK in combination with the Grails CLI, you will receive the following error from Maven/Aether:

[ERROR] Failed to determine Java version for profile java7 @
at org.apache.maven.model.building.DefaultModelProblemCollector.newModelBuildingException(DefaultModelProblemCollector.java:195)
at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:416)
at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:368)
at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:359)
at grails.util.BuildSettings.doResolve(BuildSettings.groovy:513)
at grails.util.BuildSettings.doResolve(BuildSettings.groovy)
at grails.util.BuildSettings$_getDefaultBuildDependencies_closure17.doCall(BuildSettings.groovy:774)
at grails.util.BuildSettings$_getDefaultBuildDependencies_closure17.doCall(BuildSettings.groovy)
at grails.util.BuildSettings.getDefaultBuildDependencies(BuildSettings.groovy:768)
at grails.util.BuildSettings.getBuildDependencies(BuildSettings.groovy:673)

The issue here is that the [DefaultModelBuilder](https://github.com/apache/maven/blob/maven-3.1.1/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java) uses the [JdkVersionProfileActivator](https://github.com/apache/maven/blob/maven-3.1.1/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java) to validate the Maven profile contained in the POM file. The activator in turn looks for the presence of the `java.version` system property to determine if the profile should be activate based on the version of the JVM running the project. However, because Grails is programmatically setting up the model building request, Maven/Aether does not have access to the system properties. Therefore, we must pass the system properties through to the programmatically created `DefaultModelBuildingRequest` to ensure that the Maven/Aether model validation code has access to all the properties it needs to check in order to successfully validate the POM file.

This change has been tested with a project that uses JDK-based profile activation to verify that it does indeed solve the issue referenced above.