问题
I have a maven project where I create two packagings. One is a tar.gz file (for some targets) and an RPM for linux targets that can use RPM. I use the maven-assembly-plugin for the tar.gz file. I use maven-rpm-plugin for the RPM packaging.
The assembly plug allows the specification of a true option that will replace any maven properties in the target files. For example (from my pom):
<fileSet>
<directory>${basedir}/src/resources/</directory>
<outputDirectory>/</outputDirectory>
<filtered>true</filtered>
<includes>
<include>**/*.sh</include>
</includes>
<fileMode>0774</fileMode>
</fileSet>
My .sh file has a section in it that declared the jar file for the java command line:
java -cp $ARGO_HOME/client/lib/${project.artifactId}-${project.version}.jar
When I use the maven assembly plugin as defined above, the ${project.artifactId}-${project.version} gets translated accordingly.
However, when I use the same files for my RPM build these variables are not replaced.
Is there a way I can get the RPM configuration to work like the Assembly config? I cannot find any docs that tell me this is possible. BTW my RPM config looks like this:
<mapping>
<directory>/opt/argo/client/bin</directory>
<directoryIncluded>false</directoryIncluded>
<username>argo</username>
<groupname>argogroup</groupname>
<filemode>744</filemode>
<sources>
<source>
<location>src/resources/client/bin</location>
<includes>
<include>*.sh</include>
</includes>
</source>
</sources>
</mapping>
What I would love is to just put true in the mapping and call it a day. Is there any way to do this using the maven-rpm-plugin?
I am thinking of using the maven-replacer-plugin, but that is not as elegant as I'd like.
Any suggestions?
回答1:
Had the same issue using the postinstallScriptlet configuration, which was solved by following the orientation to use the maven-resources-plugin, that could be seen here: does an external script in rpm-maven-plugin have access to maven properties
So your configuration should be:
for maven-resources-plugin:
<configuration>
<outputDirectory>${basedir}/target/classes/scripts</outputDirectory>
<resources>
<resource>
<directory>src/resources/client/bin</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
for rpm-maven-plugin:
<mapping>
<directory>/opt/argo/client/bin</directory>
<directoryIncluded>false</directoryIncluded>
<username>argo</username>
<groupname>argogroup</groupname>
<filemode>744</filemode>
<sources>
<source>
<location>${basedir}/target/classes/scripts</location>
<includes>
<include>*.sh</include>
</includes>
</source>
</sources>
</mapping>
This way the maven-resources-plugin will filter your maven properties to the copied file, that will be referred on rpm-maven-plugin
回答2:
Take look at POM Reference, Resources:
▪ filtering: is
true
orfalse
, denoting if filtering is to be enabled for this resource. ... resources can also use properties that are by default defined in the POM (such as ${project.version})
来源:https://stackoverflow.com/questions/31461193/using-maven-rpm-plugin-how-do-i-to-replace-text-in-files-similar-to-the-assembly