I think you have hit a bug. Please file a JIRA. If you can provide a test case or a patch with a test case I can take a look at applying it and rolling the required releases
On 21 May 2013 15:43, Laura Llewellyn <[email protected]> wrote: > I am having difficulty setting multiple environment variables in my invoker > plugin configuration and having them appear in the test invocations. Here > is the invoker plugin config: > > <plugin> > <artifactId>maven-invoker-plugin</artifactId> > <version>1.8</version> > <configuration> > <projectsDirectory>src/it</projectsDirectory> > > <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> > <settingsFile>src/it/settings.xml</settingsFile> > <addTestClassPath>true</addTestClassPath> > > > <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath> > <postBuildHookScript>verify</postBuildHookScript> > <properties> > <enforcer.skip>false</enforcer.skip> > </properties> > </configuration> > <executions> > <execution> > <id>pre-integration-test</id> > <goals> > <goal>install</goal> > </goals> > </execution> > <execution> > <id>project-validation</id> > <goals> > <goal>run</goal> > </goals> > <configuration> > <environmentVariables> > <A_PROP>white</A_PROP> > <Z_PROP>blue</Z_PROP> > </environmentVariables> > <pomIncludes> > <pomInclude>**/pom.xml</pomInclude> > </pomIncludes> > <debug>true</debug> > </configuration> > </execution> > </executions> > </plugin> > > My test project (/src/it/multEnvVar/pom.xml) uses the antrun plugin to echo > the environment properties and the enforcer plugin to verify the env. > variables were set properly. > > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-antrun-plugin</artifactId> > <version>1.7</version> > <executions> > <execution> > <id>echo</id> > <phase>validate</phase> > <goals> > <goal>run</goal> > </goals> > <configuration> > <target> > <property environment="env" /> > <echoproperties /> > </target> > </configuration> > </execution> > </executions> > </plugin> > > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-enforcer-plugin</artifactId> > <version>1.2</version> > <executions> > <execution> > <id>enforce-env-properties</id> > <phase>process-sources</phase> > <goals> > <goal>enforce</goal> > </goals> > <configuration> > <rules> > <requireProperty> > <property>env.A_PROP</property> > <message>### Missing property > 'A_PROP'</message> > </requireProperty> > <requireProperty> > <property>env.Z_PROP</property> > <message>### Missing property > 'Z_PROP'</message> > </requireProperty> > </rules> > </configuration> > </execution> > </executions> > </plugin> > > I run mvn -X clean integration-test. The invoker plugin config clearly > shows that the environment properties are there: > > [INFO] --- maven-invoker-plugin:1.8:run (project-validation) @ > maven-env-test --- > [DEBUG] Configuring mojo > org.apache.maven.plugins:maven-invoker-plugin:1.8:run from plugin realm > ClassRealm[plugin>org.apache.maven.plugins:maven-invoker-plugin:1.8, > parent: sun.misc.Launcher$AppClassLoader@26c94114] > [DEBUG] Configuring mojo > 'org.apache.maven.plugins:maven-invoker-plugin:1.8:run' with basic > configurator --> > [DEBUG] (f) addTestClassPath = true > [DEBUG] (f) cloneAllFiles = false > [DEBUG] (f) cloneClean = false > [DEBUG] (f) cloneProjectsTo = C:\sandbox\maven-env-test\target\it > [DEBUG] (f) debug = true > [DEBUG] (f) disableReports = false > [DEBUG] (f) encoding = UTF-8 > *[DEBUG] (f) environmentVariables = {A_PROP=white, Z_PROP=blue}* > [DEBUG] (f) goalsFile = goals.txt > [DEBUG] (f) ignoreFailures = false > [DEBUG] (f) invokerPropertiesFile = invoker.properties > [DEBUG] (f) localRepositoryPath = > C:\sandbox\maven-env-test\target\local-repo > [DEBUG] (f) mergeUserSettings = false > [DEBUG] (f) noLog = false > [DEBUG] (f) parallelThreads = 1 > [DEBUG] (f) pluginArtifacts = > [org.apache.maven.plugins:maven-invoker-plugin:maven-plugin:1.8:, > org.apache.maven.shared:maven-invoker:jar:2.1.1:compile, > org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile, > org.slf4j:slf4j-jdk14:jar:1.5.6:runtime, > org.slf4j:slf4j-api:jar:1.5.6:runtime, > org.slf4j:jcl-over-slf4j:jar:1.5.6:runtime, junit:junit:jar:3.8.1:compile, > commons-cli:commons-cli:jar:1.2:compile, > org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-4:compile, > backport-util-concurrent:backport-util-concurrent:jar:3.1:compile, > org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile, > org.sonatype.plexus:plexus-cipher:jar:1.4:compile, > org.apache.maven.reporting:maven-reporting-api:jar:3.0:compile, > org.apache.maven.reporting:maven-reporting-impl:jar:2.1:compile, > org.apache.maven.doxia:doxia-core:jar:1.1.2:compile, > xerces:xercesImpl:jar:2.8.1:compile, > commons-lang:commons-lang:jar:2.4:compile, > commons-httpclient:commons-httpclient:jar:3.1:compile, > commons-codec:commons-codec:jar:1.2:compile, > commons-validator:commons-validator:jar:1.2.0:compile, > commons-beanutils:commons-beanutils:jar:1.7.0:compile, > commons-digester:commons-digester:jar:1.6:compile, > commons-logging:commons-logging:jar:1.0.4:compile, > oro:oro:jar:2.0.8:compile, xml-apis:xml-apis:jar:1.0.b2:compile, > org.apache.maven.shared:maven-script-interpreter:jar:1.1:compile, > org.codehaus.groovy:groovy:jar:2.0.1:compile, > antlr:antlr:jar:2.7.7:compile, org.ow2.asm:asm-tree:jar:4.0:compile, > org.ow2.asm:asm-commons:jar:4.0:compile, org.ow2.asm:asm:jar:4.0:compile, > org.ow2.asm:asm-util:jar:4.0:compile, > org.ow2.asm:asm-analysis:jar:4.0:compile, > org.apache.maven.doxia:doxia-sink-api:jar:1.1.4:compile, > org.apache.maven.doxia:doxia-logging-api:jar:1.1.4:compile, > org.apache.maven.doxia:doxia-site-renderer:jar:1.1.4:compile, > org.apache.maven.doxia:doxia-decoration-model:jar:1.1.4:compile, > org.apache.maven.doxia:doxia-module-xhtml:jar:1.1.4:compile, > org.apache.maven.doxia:doxia-module-fml:jar:1.1.4:compile, > org.codehaus.plexus:plexus-velocity:jar:1.1.7:compile, > org.apache.velocity:velocity:jar:1.5:compile, > commons-collections:commons-collections:jar:3.2:compile, > org.beanshell:bsh:jar:2.0b4:compile, > org.codehaus.groovy:groovy-all:jar:2.0.1:compile, > org.apache.ant:ant:jar:1.8.1:compile, > org.codehaus.plexus:plexus-utils:jar:3.0.7:compile, > commons-io:commons-io:jar:2.2:compile, > org.codehaus.plexus:plexus-interpolation:jar:1.2:compile, > org.codehaus.plexus:plexus-i18n:jar:1.0-beta-7:compile] > [DEBUG] (f) pomIncludes = [**/pom.xml] > [DEBUG] (f) postBuildHookScript = verify > [DEBUG] (f) preBuildHookScript = prebuild > [DEBUG] (f) profilesFile = profiles.txt > [DEBUG] (f) projectsDirectory = C:\sandbox\maven-env-test\src\it > [DEBUG] (f) properties = {enforcer.skip=false} > [DEBUG] (f) reportsDirectory = > C:\sandbox\maven-env-test\target\invoker-reports > [DEBUG] (f) selectorScript = selector > [DEBUG] (f) settingsFile = C:\sandbox\maven-env-test\src\it\settings.xml > [DEBUG] (f) showErrors = false > [DEBUG] (f) showVersion = false > [DEBUG] (f) skipInvocation = false > [DEBUG] (f) streamLogs = false > [DEBUG] (f) suppressSummaries = false > [DEBUG] (f) testClassPath = > [C:\sandbox\maven-env-test\target\test-classes, > C:\sandbox\maven-env-test\target\classes] > [DEBUG] (f) testPropertiesFile = test.properties > [DEBUG] (f) mojoExecution = > org.apache.maven.plugins:maven-invoker-plugin:1.8:run {execution: > project-validation} > [DEBUG] (f) project = MavenProject: > com.example:maven-env-test:0.1-SNAPSHOT @ C:\sandbox\maven-env-test\pom.xml > [DEBUG] (f) settings = > org.apache.maven.execution.SettingsAdapter@5a1b7dae > [DEBUG] -- end configuration -- > [DEBUG] Automatically excluded settings.xml from project scanning > [DEBUG] Setup projects: [] > [DEBUG] Collecting parent/child projects of multEnvVar/pom.xml > [DEBUG] Interpolate C:\sandbox\maven-env-test\target\it\multEnvVar\pom.xml > to C:\sandbox\maven-env-test\target\it\multEnvVar\pom.xml > [DEBUG] Interpolate C:\sandbox\maven-env-test\src\it\settings.xml to > C:\sandbox\maven-env-test\target\it\interpolated-settings.xml > [INFO] Building: multEnvVar\pom.xml > [DEBUG] Using invoker properties: > [DEBUG] invoker.buildResult = success > [DEBUG] invoker.debug = true > [DEBUG] invoker.goals = clean process-sources > [DEBUG] invoker.maven.version = 3.0.3+ > [DEBUG] invoker.name = Multiple env props > > The antrun plugin in the integration test debug log shows the Z_PROP is > set, but the A_PROP is not. > > [echoproperties] #Ant properties > [echoproperties] #Tue May 21 09:57:08 EDT 2013 > [echoproperties] > > ant.core.lib=C\:\\sandbox\\maven-env-test\\target\\local-repo\\org\\apache\\ant\\ant\\1.8.2\\ant-1.8.2.jar > [echoproperties] > ant.file=C\:\\sandbox\\maven-env-test\\target\\it\\multEnvVar\\pom.xml > [echoproperties] > > ant.file.maven-antrun-=C\:\\sandbox\\maven-env-test\\target\\it\\multEnvVar\\target\\antrun\\build-main.xml > [echoproperties] ant.file.type.maven-antrun-=file > [echoproperties] ant.java.version=1.7 > [echoproperties] ant.project.default-target=main > [echoproperties] ant.project.name=maven-antrun- > [echoproperties] ant.version=Apache Ant(TM) version 1.8.2 compiled on > December 20 2010 > [echoproperties] awt.toolkit=sun.awt.windows.WToolkit > [echoproperties] > basedir=C\:\\sandbox\\maven-env-test\\target\\it\\multEnvVar > [echoproperties] > classworlds.conf=c\:\\dev\\maven\\apache-maven-3.0.4\\bin\\m2.conf > [echoproperties] enforcer.skip=false > [echoproperties] env.\=\:\:=\:\:\\ > [echoproperties] > env.\=C\:=C\:\\sandbox\\maven-env-test\\target\\it\\multEnvVar > [echoproperties] env.\=EXITCODE=00000001 > [echoproperties] env.ANT_HOME=c\:\\dev\\ant\\apache-ant-1.8.2 > [echoproperties] > > env.CLASSWORLDS_JAR="c\:\\dev\\maven\\apache-maven-3.0.4\\boot\\plexus-classworlds-2.4.jar" > [echoproperties] > env.CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher > [echoproperties] env.COMMONPROGRAMFILES=C\:\\Program Files\\Common Files > [echoproperties] env.COMMONPROGRAMFILES(X86)=C\:\\Program Files > (x86)\\Common Files > [echoproperties] env.COMMONPROGRAMW6432=C\:\\Program Files\\Common Files > [echoproperties] env.COMSPEC=C\:\\Windows\\system32\\cmd.exe > [echoproperties] env.ERROR_CODE=0 > [echoproperties] env.HOME=C\:\\Users\\someUser > [echoproperties] env.HOMEDRIVE=C\: > [echoproperties] env.HOMEPATH=\\Users\\someUser > [echoproperties] env.JAVA_HOME=c\:\\Program Files\\Java\\jdk1.7.0_13 > [echoproperties] env.M2=c\:\\dev\\maven\\apache-maven-3.0.4\\bin > [echoproperties] env.M2_HOME=c\:\\dev\\maven\\apache-maven-3.0.4 > [echoproperties] env.MAVEN_CMD_LINE_ARGS=-B -X -D > maven.repo.local\=C\:\\sandbox\\maven-env-test\\target\\local-repo -s > C\:\\sandbox\\maven-env-test\\target\\it\\interpolated-settings.xml -D > enforcer.skip\=false clean process-sources > [echoproperties] env.MAVEN_JAVA_EXE="c\:\\Program > Files\\Java\\jdk1.7.0_13\\bin\\java.exe" > [echoproperties] env.MAVEN_TERMINATE_CMD=on > [echoproperties] env.OS=Windows_NT > [echoproperties] env.PATH=C\:\\thePath > [echoproperties] > env.PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.RB;.RBW > [echoproperties] env.PROGRAMDATA=C\:\\ProgramData > [echoproperties] env.PROGRAMFILES=C\:\\Program Files > [echoproperties] env.PROGRAMFILES(X86)=C\:\\Program Files (x86) > [echoproperties] env.PROGRAMW6432=C\:\\Program Files > [echoproperties] env.PROMPT=$P$G > [echoproperties] env.SESSIONNAME=Console > [echoproperties] env.SYSTEMDRIVE=C\: > [echoproperties] env.SYSTEMROOT=C\:\\Windows > [echoproperties] env.USERNAME=someUser > [echoproperties] env.Z_PROP=blue > > And not surprisingly, the enforcer plugin validation for A_PROP fails. > Z_PROP works as expected. > > I looked at the source code for the maven-invoker-plugin and the shared > Invoker component. The AbstractInvokerMojo.runBuild method has this code: > > > final InvocationRequest request = new DefaultInvocationRequest(); > .... > if ( environmentVariables != null ) > { > for ( Map.Entry<String, String> variable : > environmentVariables.entrySet() ) > { > request.addShellEnvironment( variable.getKey(), variable.getValue() > ); > } > } > > > InvocationRequest is in the shared Invoker plugin > code< > http://svn.apache.org/viewvc/maven/shared/tags/maven-invoker-2.1.1/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java?view=markup > >. > The addShellEnvironment method: > > public InvocationRequest addShellEnvironment( String name, String value ) > { > if ( this.shellEnvironmentInherited ) > { > this.shellEnvironments = new HashMap<String, String>(); > } > this.shellEnvironments.put( name, value ); > return this; > } > > shellEnvironmentInherited is true by default, and I didn't see the Invoker > plugin setting it to false. It looks to me like a new HashMap is being > created every time this method is called, meaning only one shell > environment var may be added. > > Am I missing something in the config, or have I discovered a bug? > > Thanks! > Laura >
