Hi everybody so problem is very simple I use something like this to process resources using maven:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>get-test</id>
<phase>process-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.some.test</groupId>
<artifactId>test-webapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<outputDirectory>/testPath</outputDirectory>
<destFileName>test.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Idea is pretty simple to get artifactID test-webapp placed in some path. Problem is when I check manually in repository the artifact name is something looking like this:
test-webapp-0.0.1-20160310.192210-35.jar
I think problem is with this timestamp. Is there any way to auto remove it ? Maybe Maven have something that I'm not aware of.
Related
I'm trying to do this:
<project>
[...]
<properties>
<my-artifacts>org.junit:junit,org.slf4j:slf4j</my-artifacts>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
${my-artifacts}
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
Is it possible somehow?
First you have to configure the artifactItems because artifactItems means there are several of them. To define a single artifact you have to define artifactItem as part of the list...like the following:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>[ groupId ]</groupId>
<artifactId>[ artifactId ]</artifactId>
<version>[ version ]</version>
<type>[ packaging ]</type>
<classifier> [classifier - optional] </classifier>
<overWrite>[ true or false ]</overWrite>
<outputDirectory>[ output directory ]</outputDirectory>
<destFileName>[ filename ]</destFileName>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
You can not define a list of artifact via a property. You have to define them in the configuration. You could define a single artifact via a property if you change your configuration according to the above.
https://maven.apache.org/plugins/maven-dependency-plugin/usage.html#dependency:copy
Is it still possible to download JRE from maven as a zip file, so that one can include it in the packaged product? I found this code, which doesn't work anymore:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>compile</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.oracle</groupId>
<artifactId>jre</artifactId>
<version>1.8.141</version>
<type>zip</type>
<classifier>windows-i586</classifier>
<outputDirectory>${basedir}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
UPDATE: Looks like such thing could only work after uploading the zip file to the own maven repo...
Change the version 1.8.141 to 1.8.0_131. The latest maven has this one only:
<!-- https://mvnrepository.com/artifact/com.oracle.java/jre -->
<dependency>
<groupId>com.oracle.java</groupId>
<artifactId>jre</artifactId>
<version>1.8.0_131</version>
</dependency>
EDIT :As per the comments from OP
This example here is for a dependency. What I need is a maven goal to
copy unzipped JRE to a folder. And actually I do need a specific JRE
version. So currently, the solution is to install the JRE zip file in
my maven repo and unpack it with maven goal.
Copying and unzipping the jre artifact to another location may be achieved by Maven Dependency Plugin
<project>
[...]
<dependencies>
<dependency>
<groupId>com.oracle.java</groupId>
<artifactId>jre</artifactId>
<version>1.8.0_131</version>
</dependency>
</dependencies>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>unpack</id>
<phase>validate</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.oracle.java</groupId>
<artifactId>jre</artifactId>
<type>zip</type>
<outputDirectory>/path/to/alternateLocation</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
I see a lot of similar questions. But unable to make this work.
I have tried testresources and build-helper-maven-plugin so far
Also I read in 1 thread how to write my own assembly plugin to do something like that.
But posting this again to see if there are cleaner ways that I don't know of
This is existing code and i got to fix it. The thing is when i open the jar after a successful build i am unable to find the src/test/java classes inside the jar. We got a maven build-helper-maven-plugin and maven-jar-plugin. But I don't see the test classes in it still.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>test</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I see the generated classes in a test-classes directory inside the target folder. But not inside the jar
I want them inside the jar as I am depending on that jar in another project. The other project is not compiling because its importing that test class inside src/test/Java
I cannot create a new project just for this case as I don't have that liberty.
Did you try maven-dependency-plugin (instead of build-helper-maven-plugin) in combination with maven-jar-plugin ?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version><!--$NO-MVN-MAN-VER$-->
<executions>
<execution>
<id>unpack</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>you-project-group-id</groupId>
<artifactId>you-project-artifact-id</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
I have a use case where I need to include a folder target/schemas as a source folder using maven-buildHelper plugin. I am generating a war for this project. When the source jar get created, the content of target/schemas also exists in that. I dont want add the content of target/schemas into my source jar. How can it be achieved ?
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>***************</groupId>
<artifactId>core</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>identity</artifactId>
<packaging>war</packaging>
<dependencies>
...............
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>identity</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>***************</groupId>
<artifactId>authentication-service</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
<type>jar</type>
<outputDirectory>${project.build.directory}/schemas</outputDirectory>
<includes>**/*.java,**/*.xml</includes>
</artifactItem>
<artifactItem>
<groupId>***************</groupId>
<artifactId>authorization-service</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
<type>jar</type>
<outputDirectory>${project.build.directory}/schemas</outputDirectory>
<includes>**/*.java,**/*.xml</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${maven.plugin.buildHelper}</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/schemas</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>${maven.plugin.jaxb2}</version>
<executions>
<execution>
<id>schemagen-combined</id>
<goals>
<goal>schemagen</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<includes>
<include>***************/core/identity/domain/*.java</include>
<include>***************/authentication/domain/*.java</include>
<include>***************/authorization/domain/*.java</include>
</includes>
<outputDirectory>${project.build.directory}/schemas</outputDirectory>
<generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
</configuration>
</execution>
</executions>
</plugin
</plugins>
I have a web project identity which depends on two jar authentication and authorization. In project identity, I am generating xsd using jaxb2-maven-plugin for authentication, authorization and identity sources. As the plugin jaxb2-maven-plugin, works only on sources exists in the maven source path, I am downloading sources for authentication and authorization in a folder target/schema, add this folder target/schema as a maven source folder and then running jaxb2-maven-plugin to generate xsd. Now, when I build source jar for identity, it also includes sources for authentication and authorization which I dont want.
Maven Source plugin has option for excluding selected files from created source JAR.
exclude
List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.
I have an artifact which is being built and deployed in a particular way (not as a jar file). In the course of deployment, a war file is built.
How can I configure the pom so that the artifact is also deployed as a jar file, to a different location?
Maven deploy means deploy artifact to a Maven Repository, not an application server.
Configure additional JAR artifact like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>make-a-jar</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
Attach this new artifact to your project:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file>
<!-- <file>${project.build.directory}/${project.build.finalName}.jar</file> - if finalName is defined -->
<type>jar</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
This blog post and its comments have the answer.
These three plugin configurations will allow you to build/install/deploy a jar version alongside the war.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>make-a-jar</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>
${project.build.directory}/${project.artifactId}-${project.version}.jar
</file>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<generatePom>true</generatePom>
<url>${project.distributionManagement.repository.url}</url>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file>
</configuration>
</execution>
</executions>
</plugin>
The "maven way" is to split out src/main/java into a separate module, and have the war file depend on that.
If you're absolutely resistant to that approach, you may be able to use a profile to alter the contents of the packaging element. I'm not sure if that's possible though.
Separating them is the right way to go. Forcing maven to produce a war and a jar in the same module is possible but will cause you problems down the road.
You should add the corresponding dependency of the artifact in the dependencies of the pom file.
Ex:
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>1.2.2</version>
<scope>compile</scope>
</dependency>
One way to solve this is to have the module build a jar and then use the assembly plugin to build a war file with the jar in WEB-INF/lib of that war. I would strongly recommend against this. You'd be better off having a jar project and a war project with a parent project building both modules.