Is it possible to perform a patch release in maven? I would like to create a jar containing only one class which I have changed since the release.
There is no generic way to do that, as far as I know.
However, the simplest way to do that is to create a simple assembly that will create a JAR or a ZIP containing your classes. The assembly.xml will only need to include the specified class file:
<assembly>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>target/classes/foo/bar/FooBar.class</source>
<outputDirectory>foo/bar</outputDirectory>
</file>
</files>
</assembly>
(note that I didn't test this script)
Then, after compiling (mvn clean install) your project, you will just need to run the command mvn assembly:assembly to create your ZIP file.
Related
I don't want to modify every single line to tell ivy to download ALL sources that it can of all jars. Is there a way to add just one line or property to tell ivy to get all sources that it can for all jars/binaries that it gets so it's easier for our team to step through the code when we need to.
I guess I am looking for something like mavens "mvn dependency:sources" so I can just have a separate ant target or something.
You could set a default configuration mapping in the ivy.xml file, as follows:
<configurations defaultconfmapping="compile->default;sources->sources">
<conf name="compile" description="Compile classpath"/>
<conf name="sources" description="Source jars"/>
</configurations>
This will create two groups of files. The compile classpath dependencies and the source jars.
I am using maven jar plugin to package the jar file. But it looks like maven jar plugin just only pack the stuff that stay inside target/classes. I am also want to pack all the classes in target/classes and (resource and class) files from many other directories. How can i do that with maven jar?
The resource files stays in another folder of project.
If you can't (or just don't want to) put them under src/main/resources, you can declare additional resource locations using the <resource> element:
<project>
...
<build>
...
<resources>
<resource>
<directory> [your folder here] </directory>
</resource>
</resources>
...
</build>
...
</project>
See Specifying resource directories.
The other classes are generated classes.
The convention with plugins generating sources it to generate them in target/generated-sources/<tool> and a well implemented plugin should add the specified path as a source directory (so that generated code would be compiled). When they don't, the Build Helper Maven Plugin can come to the rescue.
If you are generating classes, why don't you generate them in ${project.build.outputDirectory} (i.e. target/classes by default)? I don't think you can add a 2nd classes directory anyway.
If this doesn't help, please clarify your exact constraints and requirements.
References
Specifying resource directories
MavenPropertiesGuide
I'm using Maven and its assembly plugin to build a distribution package of my project like this:
one project assembles a basic runtime (based on Felix), with the appropriate directories and bundles, in a ZIP file.
third-party libraries are collected in one project each and either converted to OSGi bundles or, if they are already OSGi compatible, they are just copied
my own project consists of several modules that are built into OSGi bundles, too.
Now, I'm adding another project that unpacks the ZIP, drops all the other JARs into the proper directories, and repackages it for distribution. Now, my bundles might contain configuration files that I want to merge into, rather than replacing, identically named ones in the runtime assembly. How do I do that?
The files are plain text (property files), but I might run into a similar situation with XML files later.
Expanding a bit on Juergen's answer for those who stumble on this - the containerDescriptorHandler in the descriptor can take four values (v2.3), these are metaInf-services, file-aggregator, plexus, metaInf-spring. It's a bit buried in the code (found in the package org.apache.maven.plugin.assembly.filter) but it is possible to aggregate config/properties files.
Here's an example descriptor that aggregates the META-INF/services and
named property files located in com.mycompany.actions.
descriptor.xml
<assembly>
...
<containerDescriptorHandlers>
<containerDescriptorHandler>
<handlerName>metaInf-services</handlerName>
</containerDescriptorHandler>
<containerDescriptorHandler>
<handlerName>file-aggregator</handlerName>
<configuration>
<filePattern>com/mycompany/actions/action.properties</filePattern>
<outputPath>com/mycompany/actions/action.properties</outputPath>
</configuration>
</containerDescriptorHandler>
</containerDescriptorHandlers>
....
</assembly>
The file-aggregator can contain a regular expression in the filePattern to match multiple files. The following would match all files names 'action.properties'.
<filePattern>.+/action.properties</filePattern>
The metaInf-services and metaInf-spring are used for aggregating SPI and spring config files respectively whilst the plexus handler will aggregate META-INF/plexus/components.xml together.
If you need something more specialised you can add your own configuration handler by implementing ContainerDescriptorHandler and defining the component in META-INF/plexus/components.xml. You can do this by creating an upstream project which has a dependency on maven-assembly-plugin and contains your custom handler. It might be possible to do this in the same project you're assembling but I didn't try that. Implementations of the handlers can be found in org.apache.maven.plugin.assembly.filter.* package of the assembly source code.
CustomHandler.java
package com.mycompany;
import org.apache.maven.plugin.assembly.filter.ContainerDescriptorHandler;
public class CustomHandler implements ContainerDescriptorHandler {
// body not shown
}
then define the component in /src/main/resources/META-INF/plexus/components.xml
components.xml
<?xml version='1.0' encoding='UTF-8'?>
<component-set>
<components>
<component>
<role>org.apache.maven.plugin.assembly.filter.ContainerDescriptorHandler</role>
<role-hint>custom-handler</role-hint>
<implementation>com.mycompany.CustomHandler</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
</component>
</components>
</component-set>
Finally you add this as a dependency on the assembly plugin in the project you wish to assemble
pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptors>
<descriptor>...</descriptor>
</descriptors>
</configuration>
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>sample-handler</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
and define the handlerName in the descriptor
descriptor.xml
...
<containerDescriptorHandler>
<handlerName>custom-handler</handlerName>
</containerDescriptorHandler>
...
The maven-shade-plugin can also create 'uber-jars' and has some resource transforms for handling XML, licences and manifests.
J
Old question but stumbled over it while trying to solve similar problem: Assembly plugin 2.2 has capabilities to merge files: http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_containerDescriptorHandler
e.g. handlerName "metaInf-services" (will concat all META-INF/services files), "metaInf-spring" are the only ones I know of (I personally needed metaInf-services)
I don't know of a robust solution to this problem. But a bit of looking around shows that somebody has created a plugin to merge properties files. By the look of it you need to tell it which files to merge, which is a good thing as you don't want this applied willy nilly.
Assuming you have used dependency-unpack to unpack the zip to a known location, it would be a case of configuring the plugin to merge each pair of properties files and specify the appropriate target location.
You could extend the plugin to handle XML by using something like xmlmerge from EL4J, as described in this Javaworld article.
Ive also created a merge files plugin, in my case i use it to merge SQL files from various projects into a single installer SQL file which can create all the schemas/tables/static data etc for our apps in a single file, http://croche.googlecode.com/svn/docs/maven-merge-files-plugin/0.1/usage.html
https://github.com/rob19780114/merge-maven-plugin (available on maven central) also seems to do the job.
See below for an example configuration
<plugin>
<groupId>org.zcore.maven</groupId>
<artifactId>merge-maven-plugin</artifactId>
<version>0.0.3</version>
<executions>
<execution>
<id>merge</id>
<phase>generate-resources</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<mergers>
<merger>
<target>${build.outputDirectory}/output-file-1</target>
<sources>
<source>src/main/resources/file1</source>
<source>src/main/resources/file2</source>
</sources>
</merger>
<merger>
<target>${build.outputDirectory}/output-file-2</target>
<sources>
<source>src/main/resources/file3</source>
<source>src/main/resources/file4</source>
</sources>
</merger>
</mergers>
</configuration>
</execution>
</executions>
I am using Assembly plugin for maven to create an installation package.
For my packaging requirement, I need to split artifacts generated during the build and all dependencies into separate folders.
My current Assembly manifest is as follows:
<moduleSets>
<moduleSet>
<includes>
<include>test:test</include>
</includes>
<binaries>
<includeDependencies>false</includeDependencies>
<outputDirectory>lib/custom/${artifactId}</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
<moduleSet>
<includes>
<include>test:test</include>
</includes>
<binaries>
<includeDependencies>true</includeDependencies>
<excludes>
<exclude>test:test</exclude>
</excludes>
<outputDirectory>lib/thirdParty/</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
First moduleset correctly generates only currently built assembly.
However, thirdParty includes the currently built assembly as well. How would I go about excluding the files already included in the first set?
Thanks
What about using dependency:copy-dependencies? I use that to copy all deps to target/lib .
One kludgy way to do it is with the maven-antrun-plugin and an ant task. Iterate the contents of lib/custom/${artifactId} and remove any files from lib/thirdParty.
You might want to look at appassembler-maven-plugin. It lets you dump all your runtime dependency jars in a directory. You might be able to hack that up to put your main jar in one folder and then dump the dependencies into another.
I am creating an assembly with packaging=war.
I need to include few of the jars, which have been declared as project dependencies in pom.xml in my war (web-inf/lib)
How can I do this?
Edited on 15/10-
My project creates few assemblies, one of which is supposed to give packaging of type-war.
Some jar files, which are dependencies for the project(and have been declared in pom.xml)need be included in war under WEB-INF.
How can I include them or how can i point out their paths to my local nexus repository path?
Can you be more precise? By default, when you run the mvn clean install command on a war project, Maven 2 will include all dependencies in WEB-INF/lib directories, excluding the ones with the scope test and provided.
If you create your war file using an assembly, then you have an assembly.xml file, which defines the content of your final war file. In this file, you can specify the list of dependencies you want to include:
<assembly>
...
<dependencySets>
<dependencySet>
<includes>
<include>log4j:log4j</include>
<include>commons-lang:commons-lang</include>
...
</includes>
<unpack>false</unpack>
<outputDirectory>WEB-INF/lib</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
(in this example, I asked to add log4j and commons-lang dependencies).
For each dependency, you need to specify the groupId and the artifactId. The version is automatically detected regarding the list of dependencies you have set in your pom.xml file.