Maven assembly plugin: run only one descriptor - plugins

I have a project which has several custom descriptors written for the assembly plugin. Is there a way to run only one of those descriptors at a time instead of the whole bunch? I tried using the descriptors switch as documented here, passing in the full path to the one descriptor that I wanted to run, but instead it's running all of the descriptors in my app's main pom file, seeming to ignore the switch I specified.

Probably the easiest way to do so, is by using Maven Profiles.
Define some profiles in your pom.xml:
<profiles>
<profile>
<id>profile-1</id>
<properties>
<assembly-config>assem1.xml</assembly-config>
</properties>
</profile>
<profile>
<id>profile-2</id>
<properties>
<assembly-config>assem2.xml</assembly-config>
</properties>
</profile>
</profiles>
Then you use that particular property for the configuration of the assembly plugin:
...
<descriptor>src/main/assembly/${assembly-config}</descriptor>
...
Then run your maven build with the -P option: mvn -P profile-1 compile
So, summarized, if you choose a profile at buildtime, the property assembly-config will be set depending on the defined profile. The assembly configuration depends in that case on the chosen profile.
Hope this helps!

Related

Eclipse not publishing web.xml filled by Maven

Continuing my prior question (Maven: how to fill a variable in web.xml file), I realized that the values written in web.xml are not passed to the deployed web.xml.
Let me show what is happening: I am running a web application in Tomcat through WTP Eclipse. In the web.xml, I have this context-param:
<context-param>
<param-name>producao</param-name>
<param-value>${ambiente.producao}</param-value>
</context-param>
The ambiente.producao is filled according to Maven profile chosen:
<profiles>
<profile>
<id>prod</id>
<properties>
<ambiente.producao>true</ambiente.producao>
</properties>
</profile>
<profile>
<id>desenv</id>
<properties>
<ambiente.producao>false</ambiente.producao>
</properties>
</profile>
</profiles>
Also, I have a ServletContextListener implementation which will print the value of the producao param:
public void contextInitialized(ServletContextEvent event) {
logger.warn(event.getServletContext().getInitParameter("producao"));
}
Thanks to Fred Bricon tip, I was able make the Maven fill correctly the ambiente.producao variable in the web.xml copied to the target directory.
However, when I start the Tomcat and print the the producao init param, It is showed ${ambiente.producao}. Actually, when I open the web.xml present in the directory [WORKSPACE_DIR]/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/sinpo-web/WEB-INF, the producao is not filled as it should be. It was like Eclipse (or WTP or Maven) had chosen the original file instead of filled file.
Therefore, I ask if there is some missing configuration needed to make the Maven (or Eclipse) publish using the files in target directory instead the original file.
Thanks,
Rafael Afonso

Testing my code against two Eclipse releases with Tycho

I am in need to test my code against two target platforms (which can be wrong to start with, but I would like to keep the focus on the issue): Kepler and Luna.
To do this, I defined two repositories in my parent project:
<repositories>
<repository>
<id>kepler</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/kepler</url>
</repository>
<repository>
<id>luna</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/luna</url>
</repository>
</repositories>
Then I created two plugins, one for Kepler and one for Luna which declare two different dependencies (code is duplicated, but again this is a separate issue):
// Luna
Require-Bundle:
org.eclipse.e4.core.contexts;bundle-version="1.3.100"
// Kepler
Require-Bundle:
org.eclipse.e4.core.contexts;bundle-version="[1.3.0,1.3.100)"
Now, when I specify the adequate tycho.target-platform, through -D or settings.xml, and run the build with mvn clean install, one of these plugins always fails and the other one succeeds. Luna fails if I don't specify a Luna target, Kepler fails if I don't specify a Kepler target.
There must be a better way, I told myself, and I read about target-platform-configuration which I have configured with all the possible combinations of os/ws/arch.
But still it fails for one or the other. What am I doing wrong?
The problem is that you override your target platform configuration in the POM by using the deprecated -Dtycho.target-platform property. When that property is set, Tycho no longer uses the artifacts from the two p2 repositories that you have specified.
So, don't use this property (and also make sure that you don't set it your settings.xml) and your approach should work.
My answer came right after checking my ~/.m2/settings.xml:
<profile>
<id>tycho-kepler</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<tycho.targetPlatform>/usr/local/share/eclipse</tycho.targetPlatform>
</properties>
</profile>
<profile>
<id>tycho-luna</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<tycho.targetPlatform>/usr/local/share/eclipse-luna</tycho.targetPlatform>
</properties>
</profile>
Apparently these lines, even without having specified -P or the profile in the build, are added to the execution, something that I didn't now. Removing them solved the problem immediately.

importing maven project with m2e ignores active profile

I have defined a profile in my POM. Now I want to import this project with m2e. When I do so the default profile is ignored. On the other hand If I set the profile explicitly before import which profiles should be active (Import Maven Project > Advanced) then the project is imported with the correct profile.
Why is the profile is ignored when importing with m2e? If maven can determine the correct profile on command line why can't it do so with M2E?
<profiles>
<profile>
<id>important-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
... important stuff ...
Consider opening an issue at m2eclipse - Support because it is free software.

Using Maven's .m2/settings.xml throws warning in Eclipse m2e

I'm using Maven's settings.xml to override a property value for a log4j.properties file for development purposes. However, after I made this change, I now receive warnings in Eclipse m2e even though this is a normal use case:
Access "/Users/junger/.m2" directory outside of project base
directory.
(org.apache.maven.plugins:maven-resources-plugin:2.5:resources:default-resources:process-resources)
How do I remove this warning? Or, is there a bug tracking this? I couldn't find one.
In my pom.xml, I have -
<properties>
<log4j.properties.directory>src/main/java</log4j.properties.directory>
</properties>
In my settings.xml, I have -
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<log4j.properties.directory>/Users/junger/.m2/</log4j.properties.directory>
</properties>
</profile>
</profiles>
Looking at the code (the newScanner() method) of m2e, this seems to be an explicit warning when your project references files outside of its base directory.
For me, this warning is kind of justified. When you are referencing resources outside of your project's basedir, your builds might not be reproducible anymore. Your projects should rather be self contained without depending on external files.

Change a file xml with maven plugin

I´m working with maven 3, migrating the old application using hivemind and ant. I need to change The file "Hivemodule.xml" with some properties with information about enviroment, I define with profile but it doesn´t work.
I try using maven-resources-plugin but without success, perhaps it just do with properties files.
Detail: The Hivemodule.xml is inside the file jar and I want to unpack this file to turn the content of internal hivemodule configurations and after, to pack again... I´m in the unpack fase.
Here is my file in Hivemodule.xml and the parameters that I want to turn:
PROVIDER_URL="ormi://localhost:23791/"
APPLICATION_NAME="services_1_11"
SECURITY_PRINCIPAL="oc4jadmin"
SECURITY_CREDENTIAL="welcome"
For use of profiles, I edited this file:
PROVIDER_URL="${PROVIDER_URL}"
APPLICATION_NAME="${APPLICATION_NAME}"
SECURITY_PRINCIPAL="${SECURITY_PRINCIPAL}"
SECURITY_CREDENTIAL="${SECURITY_CREDENTIAL}"
In my pom.xml, the references to profile:
<profiles>
<profile>
<id>local</id>
<properties>
<PROVIDER_URL>ormi://localhost:23791/</PROVIDER_URL>
<APPLICATION_NAME>services_1_11</APPLICATION_NAME>
<SECURITY_PRINCIPAL>oc4jadmin</SECURITY_PRINCIPAL>
<SECURITY_CREDENTIAL>welcome</SECURITY_CREDENTIAL>
</properties>
</profile>
</profiles>
And my resource configurations:
<resources>
<resource>
<directory>${serviceSegPath}/${serviceName}/META-INF/</directory>
<filtering>true</filtering>
</resource>
</resources>
Is there any suggestion to solution this? Another plugin to make changes in xml file?
Perhaps this profile is not active when running maven.
mvn -P local clean install