Modifying the value of a Maven Property when Substituting it
Is there a way in Maven to convert the value of a property, such as through a simple String.replace() call, before the value is substituted into a file?
I have a situtation where I am trying to create an assembly containing maven depenedencies with a particular directory structure. In particular, I want to place each artifact into a directory sturcture that maps to its groupId. In other words, if I have artifact org.example.app:library1:jar
, I want to place it into the directory org/example/app/library1.jar
.
I tried creating an Assembly descriptor to put the dependent artifacts into a subdirectory, but I have reached a point where I cannot convert the groupId (with dot notation) into a path. Below is the dependencySet portion of the assembly file that I am using.
<dependencySets>
<dependencySet>
<开发者_开发百科;outputFileNameMapping>${artifact.groupId}/${artifact.artifactId}/${artifact.version}/${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
<outputDirectory>.</outputDirectory>
<unpack>false</unpack>
<useTransitiveDependencies>true</useTransitiveDependencies>
<useTransitiveFiltering>false</useTransitiveFiltering>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
P.S. I also investigated the Assembly plugin's repository mode, but it includes too much information (e.g. SHA1 and MD5 hashes, plus Maven POM files).
The assembly descriptor file is used by the assembly plugin and, by itself has no mechanisms to embed Maven properties such as ${my.property}. However, as a work-around you could use the maven resources plugin to "filter" the assembly descriptor file (while it is being copied from one place to another). This would enable the substitution you'd be looking for.
Then you would have the Maven assembly plugin use the filtered descriptor file.
精彩评论