maven jar deployed twice in a war module with attachClasses set to true - maven

I am trying to use module as a dependency in another project by deploying it to our nexus repository.
The problem is that maven tries to deploy the jar twice and our policy forbids to overwrite a release version.
The module is packaged as a war.
Here is my configuration.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>build-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
<configuration>
<attachClasses>true</attachClasses>
<failOnMissingWebXml>true</failOnMissingWebXml>
</configuration>
</plugin>
When I set attachClasses to false, everything goes fine and the war gets deployed, but the jar doesn't.
When I set it to true, the jar gets deployed but maven tries to deploy a second time and then the build fails.
Any idea why maven tries to deploy it twice.
(The module has a parent module, but it does not depend on any other module from the project).

The problem is probably that you defined your own execution.
Try to remove the block
<executions>
<execution>
<id>build-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>

Related

Maven: Get repository URL of a dependency

I want do display the URL to a JAR that was deployed to our maven repo at the end of my build job. (Basically the "link" where the dependency - the JAR - can be downloaded from the repository server)
So how to display the remote repository URL of a dependency on command line?
I suggest you to compose the URL from the parameters in the very pom. Example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>deploy-message</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>deploying to url=${project.distributionManagement.repository.url}/${project.groupId}/${project.artifactId}/${project.version}/${project.artifactId}-${project.version}.jar</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
(This message will appear at the same time the deploy is being performed, but you can set it to whatever phase you want. Or include it into a Maven profile.)

Only generate one war during package

By default JHipster generate 2 wars during the package phase (your_project_version.war & your_project_version.war.original). The first one is the executable jar and the second is the war you can use in a servlet container.
Is there a way to only generate the 'original' war. The executable is not required for my project and I would like to deploy the war to Nexus.
jhipster generated project will make use of spring-boot, and in particular of the spring-boot-maven-plugin, which by default binds the repackage goal to the package lifecycle phase. If you want to disable the repackaging, it should be enough to edit your pomfile, so that no execution is present for the repackage goal (by setting the bound phase to none):
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<phase>none</phase>
</execution>
</executions>
</plugin>
If you need so, you will then be able to run the goal directly, as:
mvn package spring-boot:repackage
In SpringBoot 2, removing executions did not work for me. I needed to set goal to package :
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
<phase>none</phase>
</execution>
</executions>

maven tomcat7:run terminates automaticatlly in eclipse

Guys I know its very easy to run tomcat7 plugin in maven(in eclipse) but as I'm new to maven structure I can't figure it out that I was running maven build with "tomcat:run" and was working but I switched to maven plugin tomcat7 configured in pom.xml It starts it and stopped and gives build success msg. how change i make it keep listening?
Here my tomcate plugin settings
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<addContextWarDependencies>true</addContextWarDependencies>
<fork>true</fork>
<path>/</path>
<port>8080</port>
<httpsPort>8443</httpsPort>
<keystoreFile>C:/Users/Sohail Haider/.keystore</keystoreFile>
<keystorePass>apexsohail</keystorePass>
</configuration>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war</goal>
</goals>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>
Take into account the default lifecycle in maven
So, what you are doing in the configuration is starting and stopping tomcat when you are building the project. I think that you have a webapp project and want to run tomcat so you have to remove executions tag from the configuration and just execute mvn tomcat7:run

Maven Build some modules, liferay:deploy others

I have some modules like:
|-business jar
|-dal jar
|-model jar
|-webApp war
I need to build all jar before liferay:deploy the war.
I also have a parent pom module that allow to build all modules but it doesn't deploy my war after that.
thanks
If you have defined all modules as dependencies then maven will take care that the modules build in the proper order.
By default the Liferay deploy goal is not executed. You need execute it or add some configuration to run tit automatically. e.g.
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<configuration>
<pluginType>portlet</pluginType>
</configuration>
<executions>
<execution>
<id>deploy-package</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
Does your parent pom contains all the modules in the
<modules>
<module>business-jar</module>
<module>dal-jar</module>
<module>model-jar</module>
<module>portlet</module>
<module>theme</module>
</modules>
and then make sure that your portlet/webapp war does contain
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<executions>
<execution>
<id>deploy-package</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</executions>
</plugin>

remove jar created by default in maven

I am using maven assembly plugin. in my pom.xml, pakaging type: jar and i dont use maven jar plugin.
Whenever i run mvn clean package, it create 2 jar files: one is from maven assembly, another one is created by default (due to packaging type =jar). I want to keep only the jar file created by assembly plugin only. How to do that?
You may have your reasons but I doubt that it is a good solution to skip the default jar being built and deployed.
Anyhow here is how you can disable the default jar being built.
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<id>make-assembly</id>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- some configuration of yours... -->
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<!-- put the default-jar in the none phase to skip it from being created -->
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

Resources