I know that I should be able to add the unpacked war to my assembly. I see that the parameter is unpack
, and I know that it works for other dependencies. However, it seems that I can only access it through <dependencySet>
or <moduleSet>
. I should be able to specify my project as my own module. I must be doing something wrong.
Spleen ventilation
This is the big thing I hate about Maven: Maven does an excellent job of hiding something good from you because it prevents you from doing something you don't need. I hate it when developers build Ant build.xml
files because most developers do not understand how to build, and build.xml
becomes an unreadable mess. With Maven, this is not a problem. Just configure your project and Maven will take care of this for you.
But sometimes Maven looks like a black box with a bunch of levers and buttons. You sit there, push and pull levers and buttons, trying to figure out how to get him to do what you want to do. I spend too much time trying to help developers set up their Maven projects. They want to do something completely different, like using hibernation or creating a source from WSDL files, and they have no idea how to get Maven to do what they want.
One developer describes this as a self-driving car that cannot go where you want. You can even see your destination in the window, but you cannot figure out how to manipulate the car so that you can get there.
What I want to do should be easy. I just want to create an assembly, and instead of using the packed war file, I want it to be unpacked.
In Ant, this can be done in one task. In Maven, this is a mysterious process. I think I'm close, I probably miss one small configuration parameter that will make it work, but I have been working on this for many hours.
What i finished doing
I used maven-dependency-plugin to unpack my war. I was not sure if this would work, because I do not want the dependency plugin to load the war, but it seems to understand that when I specify my war, I am talking about the current assembly and nothing is loading. (I donβt even have a war in our Maven repo).
I also had to upgrade Maven from 2.x to 3.x because I need to make sure the maven-dependency-plugin
works before the maven-assembly-plugin
. Since both are launched during the assembly packaging phase, Maven 2.x cannot guarantee an order that includes plugins.
As soon as I used this plugin, all I had to do was specify the directory where I unpacked the war in my build plugin and was included in my zip.
I still want to know how to use the <unpack>
object in the build plugin, instead of using another plugin to unpack my war. If someone tells me how to unpack in the assembly file itself, I mark this as the correct answer.
pom.xml
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.9</version> <executions> <execution> <id>unpack</id> <phase>package</phase> <goals> <goal>unpack</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/unwar/${project.artifactId}</outputDirectory> <artifactItems> <artifactItem> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <version>${project.version}</version> <type>war</type> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.5.2</version> <configuration> <finalName>${project.artifactId}</finalName> <appendAssemblyId>false</appendAssemblyId> <outputDirectory>${project.build.directory}/archive</outputDirectory> <descriptors> <descriptor>src/assembly/bin.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
bin.xml (My assembly)
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>bin</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>${project.basedir}/src/assembly/scripts</directory> <fileMode>0755</fileMode> <lineEnding>lf</lineEnding> <includes> <include>deploy.sh</include> <include>lock_build.sh</include> <include>description.sh</include> <include>url-encode.pl</include> </includes> <outputDirectory>/</outputDirectory> </fileSet> <fileSet> <directory>${project.build.directory}/unwar</directory> <outputDirectory>/</outputDirectory> </fileSet> </fileSets> </assembly>
ACTUAL ANSWER
Thanks to the khmarbaise link (see comment below), I copied this project build plugin and it almost worked. Like my attempt, he unpacked all the runtime banners, not just the one I wanted. However, he also unpacked my war.
There were only two differences between the answer to this link and my attempt:
- They included
<useProjectArtifact>true</useProjectArtifact>
, and I did not. However, this default value is true
. Removing him still allowed him to work. - They included
/
before the directory name in <outputDirectory>
. Removing this did not matter.
This meant that now it matches what I previously tried. So why did he work this time.
Turns out I tested assembly changes by simply doing mvn assembly:single
. In the end, why is the whole assembly and repackaging when I'm just trying to get the assembly to work. When you run only mvn assembly:single
- even if everything is already packaged, you will get this error:
[WARNING] Cannot include project artifact: \ com.vegicorp:myproj:war:1.0.0; \ it doesn't have an associated file or directory.
And your war is not unpacked. However, if you put the assembly in the package phase and then run mvn package
, everything will work fine.
Then I spent the time trying to just get my war, and not all the run-time things related to it. I used <includes/>
for this, but since I have a war, not a bank, I had to include the classifier in my <include>
.
Finally, everything works for me. I have this in my assembly:
<dependencySets> <dependencySet> <outputDirectory>${project.artifactId}</outputDirectory> <unpack>true</unpack> <scope>runtime</scope> <includes> <include>${project.groupId}:${project.artifactId}:*:${project.version}</include> </includes> </dependencySet> </dependencySets>
And while I run mvn package
, it works.
This is better than mine with maven-dependency-plugin
. Now all the information related to the assembly is in the assembly XML file.