How to set directoryMode Permissions for folder in assembly descriptor? - maven

I cant seem to change the output directory permissions in my assembly descriptor. It seems to be ignored entirely. The file permissions however are set correctly. I am using Maven 3.
<fileSet>
<directory>src/main/conf</directory>
<fileMode>0644</fileMode>
<directoryMode>0755/directoryMode>
<outputDirectory>conf</outputDirectory>
</fileSet>
The directories still appear as 775.
drwxrwxr-x
Is this a known bug? I even tried defining a fileset separately excluding all files and just specifying the output directory but to no avail.
Any tips or workarounds appreciated.

This appears to have been a bug (MASSEMBLY-621) with the assembly plugin. This bug was fixed in version 2.4. I too was facing this problem, upgrading the plugin from 2.3 to 2.4 resolved this issue (using Maven 2.2.1, did not test Maven 3).
Other related bugs:
MASSEMBLY-422

Related

JIB file positioning with performance impact?

We build our Java application using jib-maven 3.2.1 in a Jenkins pipeline. In the configuration we have:
<configuration>
<extraDirectories>
<paths>
<path>
<from>target/libs</from>
<into>/opt/hcl/keep/libs</into>
</path>
</paths>
</extraDirectories>
</configuration>
to provide libraries for the classpath. Worked like a charm. Recently we notices a drop in one of our performance metrics from 400ms to 1700ms. Our tester investigated and found something puzzling. When executing the following commands inside a build image and restart, the metric went back to 400ms:
cd /opt/hcl/keep/
mv libs libs-new
mkdir libs
cp libs-new/* libs/
we are puzzled what might cause that? What could we investigate?
We found a partial answer thanks to Dive. The drop happened when we upgraded dependencies to a newer but -SNAPSHOT version. Apparently gib places snapshot jars in their own layer.
Moving to a non-snapshot version fixed the performance degradation.
What is still missing (I'll update when I learn more): why the performance difference due to existence in different layer.

uglify-maven-plugin adding exclude file list

I am trying to implement uglifyjs-maven-plugin.
While using the configuration mentioned here, I am getting error like sourceDirectory is undefined or invalid.
Using the configuration like
<configuration>
<sourceDirectory>target/snapshot/javascript</sourceDirectory>
<outputDirectory>target/snapshot/javascript</outputDirectory>
</configuration>
its working fine. But how will I add exclude file list in the above configuration.
I have a js file of 900kb, when i am including that js file inside source directory, i am getting exception during maven build as " Exception in thread "main" java.lang.StackOverflowError". Can anyone help me out of this.
It looks like that while the documentation (and probably the current implementation) supports file exclusions, the version available in the repository (1.0) is older and supports only sourceDirectory.
I have not found any newer version published anywhere, so I guess the best thing we can do is compile the latest version of the plugin manually and see if it supports what the documentation says.

Maven RPM plugin not generating correct %files section

I'm building a package using the Maven RPM plugin, and it's generating the %files section in the .spec file in a way that causes conflicts during installation. I want to install a file into /usr/bin, but the .spec file contains the following directive:
%attr(755,root,root) /usr/bin
This causes the RPM install to fail due to a conflict with another package which already owns that directory.
What I would like to do is have Maven specify the filename directly, which would avoid the entire issue. Here's the mapping section for that particular file:
<mapping>
<directory>/usr/bin</directory>
<filemode>755</filemode>
<sources>
<source>
<location>src/main/scripts/foobar.sh</location>
<destination>foobar</destination>
</source>
</sources>
</mapping>
Any suggestions?
(I've opened an issue at the plugin bug tracker for this)
As pointed out in the bug, the directoryIncluded[1] mapping controls this behavior. If you set this to false you will get the behavior you desire.
[1] - http://mojo.codehaus.org/rpm-maven-plugin/map-params.html#directoryIncluded
One of the maintainers answered my question on the issue tracker. It turns out that the directoryIncluded mapping does exactly what I want.

Maven jetty plugin using wrong resource file URL

I am running a project within a vagrant box setup over my eclipse workspace. I am working on setting up a new maven project but I am having problems with the plugin using windows paths instead of the vagrant path. My windows workspace is setup in C:\Dev, so when I 'vagrant up', my entire workspace is available within my VM. In other words, /vagrant in the VM contains the contents of C:\Dev.
When I execute mvn jetty:run, everything starts up fine and all paths use the vagrant versions (/vagrant/mvn_project/target...). However, once the plugin starts scanning the project for changes, it throws the following error:
2014-02-26 01:18:53.756:WARN:oejw.WebAppContext:Scanner-0: Failed startup of context o.e.j.m.p.JettyWebAppContext#591f46d8{/,[file:/vagrant/mvn_project/web, file:/vagrant/mvn_project/target/webapps/ROOT/],STARTING}{/ROOT/]}
javax.servlet.UnavailableException: Malformed URL 'file://C:\\Dev\\mvn_project/target/webapps/ROOT/WEB-INF/dtd/web-app_2_3.dtd' : For input string: "\\Dev\\mvn_project"
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:402)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:561)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:351)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:840)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:300)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1347)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:745)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:282)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.maven.plugin.JettyRunMojo.restartWebApp(JettyRunMojo.java:532)
at org.eclipse.jetty.maven.plugin.JettyRunMojo$1.filesChanged(JettyRunMojo.java:485)
at org.eclipse.jetty.util.Scanner.reportBulkChanges(Scanner.java:681)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:539)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391)
at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:329)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Is this a bug with the plugin or is there a configuration setting I can use to set this value?
Edit: A little more context... It seems that the problem has something to do with filtered resources.
<resources>
<resource>
<directory>${project.basedir}/src/main/filtered-resources</directory>
<filtering>true</filtering>
<targetPath>${project.basedir}/target/webapps/ROOT</targetPath>
</resource>
</resources>
Changing ${project.basedir} to /vagrant/mvn_project seems to fix the problem, but clearly this is just a workaround and not a solution (won't work in CI for example).
UPDATE: It turns out, the blame is on Eclipse. Eclipse is occasionally building the project and when it does so, ${project.basedir} refers to C:\Dev\mvn_project instead of /vagrant/mvn_project. Is there a way to override ${project.basedir} without hard coding?
Simple answer: disable builds in eclipse. Uncheck Project -> Build Automatically. Always run builds from within vagrant (mvn compile). JSP hot changes still work automatically.

How to update folders automatically with IntelliJ

I have a Maven configuration that copies my web resources to a directory in target. From there it is read by Jetty. What I want (and what Eclipse always did for me) is update the target/web directory when something in the src/main/webapp directory changed. I can't get IntelliJ to do the same:
The resource configuration like this:
<resource>
<directory>src/main/webapp</directory>
<excludes>
<exclude>less/</exclude>
</excludes>
<filtering>false</filtering>
<targetPath>${project.build.directory}/web</targetPath>
</resource>
Right now I have to run the Generate sources and update folders everytime I make a change. Can't IntelliJ Detect this automatically?
Notes:
I do not build a war but a folder distribution.
I already tried moving it to target/generated-sources/web but that makes no difference.
The target/web is not marked as excluded in the module configuration.
The folder is marked as a resource folder. I tried marking it as a source folder but that made no difference.
The problem can be solved by using the File watchers plug-in. This plug-in doesn't ship with IntelliJ by default but it is very useful. From there, you can watch your *.less/html/js files and re-generate them if you edit them. In my case I run the appropriate Maven goals but you can also call the less compiler directly if you want to.
In the configuration set "Output paths to refresh" to the the custom directory you are using (in my case $OutputPath$/web). After that, any change should be refreshed automatically.
I think, yes: try pressing Ctrl+Shift+A, type "Import Maven", click the checkbox "Import Maven project automatically". This will enable auto-import which copies resources as well.

Resources