Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I put custom assembly descriptors for the Maven Assembly plugin?

Tags:

maven-2

Either I'm missing something obvious, or both the Maven book and the Maven Assembly Plugin's homepage, while describing how to write custom assembly descriptors, don't say anything about where that file has to go. Is it part of my project? Does it go into some central Maven configuration directory? Do I have to specify its location somewhere?

like image 486
Hanno Fietz Avatar asked Oct 15 '09 12:10

Hanno Fietz


People also ask

What is assembly descriptor in Maven?

This descriptor specifies the type of assembly archive to create, the contents of the assembly, and the ways in which dependencies or its modules are bundled with an assembly. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Which of the following is a type of Maven Assembly plugin's built in descriptors?

bin. Use bin as the descriptorRef of your assembly-plugin configuration in order to create a binary distribution archive of your project. This built-in descriptor produces an assembly with the classifier bin in three archive formats: tar.

Where is Assembly XML?

The default location of assemblies. xml is in the project root directory.


2 Answers

Yes, you have to specify the location. According to the Configuration and Usage page, this is done this way:

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptors>
            <descriptor>src/main/assembly/src.xml</descriptor>
          </descriptors>
        </configuration>
        [...]
</project>

Actually, I'd recommend using src/main/assembly as location.

like image 73
Pascal Thivent Avatar answered Oct 14 '22 04:10

Pascal Thivent


In a somewhat roundabout way, I was eventually able to find out. First, this page about sharing assembly descriptors indirectly gives you some hints.

My first mistake was to use descriptorRef instead of descriptor in my plugin configuration. When I fixed that, and created the directory structure shown on the page linked above, I got a series of error messages that revealed how the plugin tries to resolve the descriptor name you gave it:

[INFO] Searching for file location: /path/to/project/dependency-collection.xml

[INFO] File: /path/to/project/dependency-collection.xml does not exist.

So, putting it in the project's root should work...

[INFO] Invalid artifact specification: 'dependency-collection.xml'. Must contain at least three fields, separated by ':'.

... or loading it from a Maven artifact ...

[INFO] Failed to resolve classpath resource: /assemblies/dependency-collection.xml from classloader: ClassRealm[/plugins/org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-2@48/thread:main, parent: ClassRealm[plexus.core, parent: null]]

[INFO] Failed to resolve classpath resource: dependency-collection.xml from classloader: ClassRealm[/plugins/org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-2@48/thread:main, parent: ClassRealm[plexus.core, parent: null]]

... or putting it on the classpath of the plugin (I guess that's where the predefined descriptors are) ...

[INFO] Building URL from location: dependency-collection.xml

Error: java.net.MalformedURLException: no protocol: dependency-collection.xml

... or load it from a URL.

Nice, but this really should be documented somewhere, I think. I just put the descriptor file next to th epom.xml and it worked. I probably could've tried that before searching the web...

like image 29
Hanno Fietz Avatar answered Oct 14 '22 03:10

Hanno Fietz