Maven project variables for dependencies

本秂侑毒 提交于 2019-12-06 00:11:31
Pascal Thivent

You'll need something like ${project.dependencies[0].artifactId} where 0 is the index of the dependency of the applet in your war module (see PLXUTILS-37). And indeed, using resources filtering should work.

Update: It appears that there is bug in the Maven Resources Plugin, this property doesn't get filtered as mentioned in this question. You may have to use the workaround suggested in this answer.

As I understand it you are trying to keep the version up to date, while expecting the rest to stay the same. There are two alternatives.

The first is to remove the version from the name so that the HTML need not change. You can see a practical example by searching for archiva-applet here: http://svn.apache.org/repos/asf/archiva/tags/archiva-1.3/archiva-modules/archiva-web/archiva-webapp/pom.xml

In this example, since you don't want the applet in WEB-INF/classes anyway, it is omitted from the webapp, and then included via the Dependency plugin:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.0</version>
  <executions>
    <execution>
      <id>copy</id>
      <phase>process-resources</phase>
      <goals>
        <goal>copy</goal>
      </goals>
      <configuration>
        <artifactItems>
          <artifactItem>
            <groupId>${project.groupId}</groupId>
            <artifactId>archiva-applet</artifactId>
            <version>${project.version}</version>
            <outputDirectory>src/main/webapp</outputDirectory>
            <destFileName>archiva-applet.jar</destFileName>
          </artifactItem>
        </artifactItems>
      </configuration>
    </execution>
  </executions>
</plugin>

If you are using Maven 2.1.0+ you can use the prepare-package phase and copy it straight to the output without modifying your source directory.

You then refer to the applet in HTML with the single name.

An alternative solution if you want to continue filtering and keep the version, is to use a shared property:

<properties>
  <applet.version>1.2.3</applet.version>
</properties>

...

<dependency>
  <groupId>my.group</groupId>
  <artifactId>my.applet</artifactId>
  <version>${applet.version}</version>
</dependency>

...

You can then use ${applet.version} in the HTML and still only have to change it in one place.

From http://docs.codehaus.org/display/MAVENUSER/MavenPropertiesGuide:

${project.build.finalName} refers to the final name of the file created when the built project is packaged

Another option you have is to change set ${project.build.finalName} to a static string in your POM:

<build>
    <finalName>foo</finalName>
</build>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!