Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 352494

Summary: Resource filtering not working correctly
Product: z_Archived Reporter: Matthew Lieder <matthew.lieder>
Component: m2eAssignee: Project Inbox <m2e.core-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: igor
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
complete standalone example project none

Description Matthew Lieder CLA 2011-07-19 14:20:54 EDT
Build Identifier: 20110615-0604

We use the buildnumber plugin to put a timestamp into a properties file and it doesn't work anymore in Eclipse after we've upgraded to m2e 1.0 (works fine from the command line). According to Igor it's a more global problem with "project properties set by one mojo are not visible to mojos executed later in the build lifecycle".

Reproducible: Always

Steps to Reproduce:
To reproduce yourself, create an app.properties with the following contents:

buildnumber=${buildNumber}
project.version=${project.version}

And then put the following in your pom.xml:

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>app.properties</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.0-beta-1</version> <!-- can't update to newer version due to MOJO-1463 -->
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>create</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <format>{0,date,yyMMddHHmm}</format>
                    <items>
                        <item>timestamp</item>
                    </items>
                </configuration>
            </plugin>
        </plugins>
    </build>

${project.version} gets resolved fine, from Eclipse or the command line, but ${buildNumber} only gets resolves if run from the command line. I've tried every phase I can think of, to no avail.
Comment 1 Igor Fedorenko CLA 2011-09-13 21:55:57 EDT
This is closely related or the same as Bug 349586
Comment 2 Igor Fedorenko CLA 2011-09-22 22:04:16 EDT

*** This bug has been marked as a duplicate of bug 349586 ***
Comment 3 Igor Fedorenko CLA 2011-09-30 13:13:32 EDT
Created attachment 204400 [details]
complete standalone example project

I've attached a complete standalone example project that demonstrates that m2e 1.1 executes buildnumber-maven-plugin during workspace build and makes ${buildNumber} property available to other maven plugins (resources-plugin in this example).

Beware that buildnumber-maven-plugin generates new property value on each execution, which is likely not the desired behaviour inside eclipse works.
Comment 4 Matthew Lieder CLA 2011-09-30 13:23:43 EDT
Thanks, adding the following XML to the testcase's POM did the trick:

		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.eclipse.m2e</groupId>
					<artifactId>lifecycle-mapping</artifactId>
					<version>1.0.0</version>
					<configuration>
						<lifecycleMappingMetadata>
							<pluginExecutions>
								<pluginExecution>
									<pluginExecutionFilter>
										<groupId>org.codehaus.mojo</groupId>
										<artifactId>buildnumber-maven-plugin</artifactId>
										<versionRange>[0,)</versionRange>
										<goals>
											<goal>create</goal>
										</goals>
									</pluginExecutionFilter>
									<action>
										<execute>
											<runOnConfiguration>true</runOnConfiguration>
											<runOnIncremental>true</runOnIncremental>
										</execute>
									</action>
								</pluginExecution>
							</pluginExecutions>
						</lifecycleMappingMetadata>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>

Is that going to be documented somewhere? I doubt many developers are going to think to do that when they encounter this issue :/.

Changing every execution is fine for my uses :)
Comment 5 Denis Roy CLA 2021-04-19 13:24:02 EDT
Moved to https://github.com/eclipse-m2e/m2e-core/issues/