Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-14906

Properties not propagated/resolved from profile to maven-surefire-plugin

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • maven-plugin
    • None

      We use jacoco in our projects, but we disable it on jenkins by setting the jacoco.skip property to true. The problem is that we insert the jacoco command line via a property into the maven-surefire plugin to inject it. When jacoco is disabled this property does not exist and we end up with the string ${jacocoArgLine} in our command line. To work around that we have a profile that set ${jacocoArgLine} to an empty string when we use the property jacoco.skip. This works well with maven alone but not when the build is made via jenkins.

      With jenkins, this property ends up being replaced with the "null" string, breaking our test run:

      Forking command line: cmd.exe /X /C "D:\tools\jdk\jdk6_sun_27\jre\bin\java null -Xmx1G -server -jar ..."
      java.lang.NoClassDefFoundError: null
      Caused by: java.lang.ClassNotFoundException: null
      	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
      Could not find the main class: null.  Program will exit.
      Exception in thread "main" 
      

      Here are the different parts of the setup:
      The part of the parent pom defining the profile to set to an empty string the missing property:

      <!-- Shared Profiles -->
      	<profiles>
      		<profile>
      			<!-- When jacoco is disabled, the jacocoArgLine property still needs to exist -->
      			<id>noJacoco</id>
      			<activation>
      				<property>
      					<name>jacoco.skip</name>
      				</property>
      			</activation>
      			<properties>
      				<jacocoArgLine></jacocoArgLine>
      			</properties>
      		</profile>
      	</profiles>
      

      The part of the project pom configuring jacoco and injecting it in the test command line:

      <!-- Java Code Coverage plugin -->
      			<plugin>
      				<groupId>org.jacoco</groupId>
      				<artifactId>jacoco-maven-plugin</artifactId>
      				<executions>
      					<execution>
      						<configuration>
      							<propertyName>jacocoArgLine</propertyName>
      						</configuration>
      						<goals>
      							<goal>prepare-agent</goal>
      						</goals>
      					</execution>
      					<execution>
      						<id>report</id>
      						<phase>prepare-package</phase>
      						<goals>
      							<goal>report</goal>
      						</goals>
      					</execution>
      				</executions>
      			</plugin>
      
      			<plugin>
      				<groupId>org.apache.maven.plugins</groupId>
      				<artifactId>maven-surefire-plugin</artifactId>
      				<configuration>
      					<includes>
      						<include>**/*Test.java</include>
      					</includes>
      					<excludes>
      						<exclude>${test.exclude}</exclude>
      						<exclude>**/Test*$*</exclude>
      					</excludes>
      					<argLine>${jacocoArgLine} ${jvm.args}</argLine>
      				</configuration>
      			</plugin>
      

      We tried using a non empty line in our noJacoco profile to avoid this but this does not help, we still end up with "null" in our command line.

          [JENKINS-14906] Properties not propagated/resolved from profile to maven-surefire-plugin

          evernat added a comment -

          Is it reproduced with a recent Jenkins version?

          evernat added a comment - Is it reproduced with a recent Jenkins version?

            Unassigned Unassigned
            olivier Olivier Jolit
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: