Maven Resources Plugin
  1. Maven Resources Plugin
  2. MRESOURCES-118

${project.dependencies[0].artifactId} is not expanded by resource filtering

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.3, 2.4, 2.4.1
    • Fix Version/s: None
    • Component/s: interpolation
    • Labels:
      None
    • Environment:
      Maven 2.2.1, Ubuntu 9.10, Java 6u16
    • Number of attachments :
      1

      Description

      When filtering resources, $

      {project.dependencies[0].artifactId} is not expanded (remains unchanged in the output file).

      I've tried to define a property in my pom to workaround this issue:

      <properties>
      <myartifact>${project.dependencies[0].artifactId}

      </myartifact>
      </properties>

      But, still, filtering the following file:

      <somenode>
        <fileName>${project.dependencies[0].artifactId}</fileName>
        <fileName>${myartifact}</fileName>
      </somenode>
      

      Produces the following unexpected result:

      <somenode>
        <fileName>${project.dependencies[0].artifactId}</fileName>
        <fileName>${project.dependencies[0].artifactId}</fileName>
      </somenode>
      

      The only working workaround I've found is to use the antrun plugin:

      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>process-resources</phase>
            <configuration>
              <tasks>
                <echo>${project.dependencies[0].artifactId}</echo>
                <echo>${artifactId}</echo>
                <replace file="${project.build.outputDirectory}/my.xml" token="@@@" value="${project.dependencies[0].artifactId}"/> 
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      

      I didn't test all cases but this problem may affect all "indexed" properties (as defined in PLXUTILS-37).

      I'm attaching a sample project demonstrating this problem.

        Issue Links

          Activity

          Hide
          Emeric MARTINEAU added a comment - - edited

          Hi,

          I trie this,

          <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
          	<modelVersion>4.0.0</modelVersion>
          	<groupId>fr.emeric</groupId>
          	<artifactId>titi</artifactId>
          	<packaging>war</packaging>
          	<version>0.0.1-SNAPSHOT</version>
          	<name>Kiko lolo</name>
          
          	<dependencies>
          		<dependency>
          			<groupId>org.apache.maven</groupId>
          			<artifactId>maven-plugin-api</artifactId>
          			<version>2.0.6</version>
          		</dependency>
          	</dependencies>
          
          	<properties>
          		<myVar>${project.dependencies[0].artifactId}</myVar>
          	</properties>
          
          	<build>
          		<resources>
          			<resource>
          				<directory>src/main/resources</directory>
          				<filtering>true</filtering>
          			</resource>
          		</resources>
          		
          		<plugins>
          			<plugin>
          				<artifactId>maven-antrun-plugin</artifactId>
          				<executions>
          					<execution>
          						<phase>generate-sources</phase>
          						<configuration>
          							<tasks>
          								<echo>${project.compileClasspathElements}</echo>
          								<echo>${project.dependencies[0].artifactId}</echo>
          								<echo>${myVar}</echo>
          							</tasks>
          						</configuration>
          						<goals>
          							<goal>run</goal>
          						</goals>
          					</execution>
          				</executions>
          			</plugin>
          		</plugins>
          	</build>
          </project>
          

          and I have the result :

          [INFO] Executing tasks
               [echo] [D:\DONNEES\emeric\workspace_eclipse\generique-projet-js\target\classes, D:\DONNEES\emeric\workspace_eclipse\.m2\repository\org\apache\maven\maven-plugin-api\2.0.6\maven-plugin-api-2.0.6.jar]
               [echo] maven-plugin-api
               [echo] maven-plugin-api
          [INFO] Executed tasks
          

          In src/main/resources I have a file test.properties :

          project.compileClasspathElements=${project.compileClasspathElements}
          project.dependencies[0].artifactId=${project.dependencies[0].artifactId}
          myVar=${myVar}
          

          I have result :

          project.compileClasspathElements=[D:\\DONNEES\\emeric\\workspace_eclipse\\generique-projet-js\\target\\classes]
          project.dependencies[0].artifactId=${project.dependencies[0].artifactId}
          myVar=${project.dependencies[0].artifactId}
          

          I think project.dependencies anly avaible in pom file.

          If you see http://jira.codehaus.org/browse/PLXUTILS-37
          I understand this properties only scope on pom not a all access properties.

          Can you explain your use case ?
          Why want this properties to understand this issue and https://jira.codehaus.org/browse/MRESOURCES-31

          PS : I think MRESOURCES-31 Is duplicate of this issue.

          Show
          Emeric MARTINEAU added a comment - - edited Hi, I trie this, <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelVersion> 4.0.0 </modelVersion> <groupId> fr.emeric </groupId> <artifactId> titi </artifactId> <packaging> war </packaging> <version> 0.0.1-SNAPSHOT </version> <name> Kiko lolo </name> <dependencies> <dependency> <groupId> org.apache.maven </groupId> <artifactId> maven-plugin-api </artifactId> <version> 2.0.6 </version> </dependency> </dependencies> <properties> <myVar> ${project.dependencies[0].artifactId} </myVar> </properties> <build> <resources> <resource> <directory> src/main/resources </directory> <filtering> true </filtering> </resource> </resources> <plugins> <plugin> <artifactId> maven-antrun-plugin </artifactId> <executions> <execution> <phase> generate-sources </phase> <configuration> <tasks> <echo> ${project.compileClasspathElements} </echo> <echo> ${project.dependencies[0].artifactId} </echo> <echo> ${myVar} </echo> </tasks> </configuration> <goals> <goal> run </goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> and I have the result : [INFO] Executing tasks [echo] [D:\DONNEES\emeric\workspace_eclipse\generique-projet-js\target\classes, D:\DONNEES\emeric\workspace_eclipse\.m2\repository\org\apache\maven\maven-plugin-api\2.0.6\maven-plugin-api-2.0.6.jar] [echo] maven-plugin-api [echo] maven-plugin-api [INFO] Executed tasks In src/main/resources I have a file test.properties : project.compileClasspathElements=${project.compileClasspathElements} project.dependencies[0].artifactId=${project.dependencies[0].artifactId} myVar=${myVar} I have result : project.compileClasspathElements=[D:\\DONNEES\\emeric\\workspace_eclipse\\generique-projet-js\\target\\classes] project.dependencies[0].artifactId=${project.dependencies[0].artifactId} myVar=${project.dependencies[0].artifactId} I think project.dependencies anly avaible in pom file. If you see http://jira.codehaus.org/browse/PLXUTILS-37 I understand this properties only scope on pom not a all access properties. Can you explain your use case ? Why want this properties to understand this issue and https://jira.codehaus.org/browse/MRESOURCES-31 PS : I think MRESOURCES-31 Is duplicate of this issue.
          Hide
          Emeric MARTINEAU added a comment -

          Hi,

          after search, "project.dependencies[0].artifactId" and "project.compileClasspathElements" is not properties.

          Is only avaible in plugin execution scope by plexus.
          Properties are evaluate just after loading project, and if not found, there are not substitued.
          Is not a maven resource bug, is how Maven/Plexus work.

          I don't really understand why you need this but you may have this in file by implement your own filter by using "mavenFilteringHints" option.
          See http://maven.apache.org/plugins/maven-resources-plugin/examples/custom-resource-filters.html for more information.

          I think this bug and number 31 can be close.

          Regards,

          Show
          Emeric MARTINEAU added a comment - Hi, after search, "project.dependencies [0] .artifactId" and "project.compileClasspathElements" is not properties. Is only avaible in plugin execution scope by plexus. Properties are evaluate just after loading project, and if not found, there are not substitued. Is not a maven resource bug, is how Maven/Plexus work. I don't really understand why you need this but you may have this in file by implement your own filter by using "mavenFilteringHints" option. See http://maven.apache.org/plugins/maven-resources-plugin/examples/custom-resource-filters.html for more information. I think this bug and number 31 can be close. Regards,

            People

            • Assignee:
              Unassigned
              Reporter:
              Pascal Thivent
            • Votes:
              5 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: