11

The maven plugin works very slow for me. In my project the webapp folder has nearly 15000 small files (images, jsp, css, etc). When I assemble it with the maven, it first copies all files to the target/myProject-1.0.0 directory, then builds myProject-1.0.0.war file from it. The copy process takes 10 minutes, building the .war takes 2 minutes.

As I see the build could be much faster if the .war file will be assembled straight from the webapp folder. Is it possible to do?

kan
  • 28,279
  • 7
  • 71
  • 101
  • Straight from the `src/main/webapp` folder? Then what about depenencies, resources, etc? – maba Oct 10 '12 at 11:38
  • @maba Sure, why not? The jar.exe could archive files from multiple locations. The ant task `` does the trick easily. – kan Oct 10 '12 at 11:44
  • It's not the maven way. You could use the [`maven-antrun-plugin`](http://maven.apache.org/plugins/maven-antrun-plugin/) to use that ant task. – maba Oct 10 '12 at 11:52
  • 1
    @maba Not sure what is wrong with the maven way, it's just matter of performance optimization - how to build an artifact in most efficient way. – kan Oct 10 '12 at 12:17
  • What if you try with parallel builds. According to [**Parallel builds in Maven 3**](https://cwiki.apache.org/MAVEN/parallel-builds-in-maven-3.html) the `maven-war-plugin` is supported. – maba Oct 10 '12 at 12:30
  • 2
    @maba Parallel build is to use several CPU cores. My problem is to copy 15000 files, which is I/O. – kan Oct 10 '12 at 15:39

3 Answers3

5

In the configuration section for the war plugin, use warSourceExcludes to exclude unneeded files and directories. In the example below, the directories components and node_modules will be excluded from the exploded war as well as from the final war. In my case this reduced the build time from 3 minutes to 14 seconds.

        <configuration>
              <warSourceExcludes>
                components/**,
                node_modules/**
              </warSourceExcludes>
        </configuration>
Victor Ionescu
  • 1,967
  • 2
  • 21
  • 24
4

I suggest that you use the use the war:inplace goal of maven-war-plugin together with a custom maven-antrun-plugin task.

The war:inplace will generate the webapp in the WAR source directory. It will create all necessary extra folders under webapp.

The antrun:run can be customized to create the war according to your special requirements.

This will potentially improve the performance since most of those resource files you have will still be in the webapp folder and not being copied.

maba
  • 47,113
  • 10
  • 108
  • 118
  • It saves some of the absurd copying but war:inplace also copies all libraries into WEB-INF/lib, which is also unneccesary and troublesome. 8-( Did anybody actually try this? – Dr. Hans-Peter Störr Nov 08 '12 at 10:27
4

Just want to mention that there is a useCache setting which significantly increases performance (~3 minute instead of 12). However it is acceptable for development only, not for CI-server which should always do clean builds.

kan
  • 28,279
  • 7
  • 71
  • 101