7

I'm running against a brick with Eclipse.

I will try to explain. I'm working on a project that "abused" of maven overlays and have many modules that have Javascript and LESS files inside the webapp.

We managed to config maven to explode the dependencies on a directory where maven-frontend-plugin would process (using nodejs) to generate the final compiled JS and CSS files.

This is working perfectly when I'm using pure maven. However, on Eclipse, this not ends to work correctly. The main reason is that Eclipse simple ignores the execution config of maven-war-plugin that explodes the dependencies. Instead, it simple executes the default maven-war-plugin:explode.

I need to fix it, as is the biggest roadblock to get a modern frontend develop environment (using nodejs, npm and gulp to transpile JS and LESS).

Extracted from our main pom.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>make-webapp-compress</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <mkdir dir="${project.build.directory}/webapp-exploded" />
                    <mkdir dir="${project.build.directory}/webapp-compress" />
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <executions>
        <execution>
            <id>parent-resources-less</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>exploded</goal>
            </goals>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <warSourceExcludes>**/*.ftl,**/*.vm,**/*.xml,WEB-INF/,META-INF/</warSourceExcludes>
                <warSourceIncludes>**/*.css,**/*.less,**/*.js</warSourceIncludes>
                <webappDirectory>${project.build.directory}/webapp-exploded</webappDirectory>
                <webResources>
                    <resource>
                        <directory>src/main/webapp</directory>
                    </resource>
                </webResources>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.eclipse.m2e</groupId>
    <artifactId>lifecycle-mapping</artifactId>
    <version>1.0.0</version>
    <configuration>
        <lifecycleMappingMetadata>
            <pluginExecutions>
                <pluginExecution>
                    <pluginExecutionFilter>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <versionRange>[1.8,]</versionRange>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </pluginExecutionFilter>
                    <action>
                        <execute />
                    </action>
                </pluginExecution>
                <pluginExecution>
                    <pluginExecutionFilter>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <versionRange>[3.0.0,]</versionRange>
                        <goals>
                            <goal>exploded</goal>
                        </goals>
                    </pluginExecutionFilter>
                    <action>
                        <execute />
                    </action>
                </pluginExecution>
            </pluginExecutions>
        </lifecycleMappingMetadata>
    </configuration>
</plugin>
Zardoz89
  • 590
  • 5
  • 17

1 Answers1

2

You can try using the plugin "maven-dependency-plugin". I used this in my project to copy the dependencies to the desired specific output destination. I am attaching the sample config, update this as per your requirement.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/pipeline/lib</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Jibran
  • 873
  • 7
  • 12
  • Helpful, but not ends to work. I config maven-dependency-plugin to execute unpack-dependencies at generate-sources phase. And I setup gulp to copy some stuff from src/main/webapp to webapp-exploded. It works when I ran maven directly, but Eclipses simply ignores my webapp-compress directory! And I put it on webResources and verify that the generated war it's correct. – Zardoz89 Nov 08 '18 at 15:51
  • Did the issue got resolved? I think you need to specify the webapp-compress directory as the resources, coz maven needs to know what is the external dependency directory other than default resources. – Jibran Nov 09 '18 at 07:23
  • Works as a alternative to maven-war-plugin:exploded. I added "webapp-compress" to the node "webResources/resources" and maven generates correctly the WAR file. However Eclipse ignores it. Do you mean that I should add webapp-exploded to another site, like "build/resources/resource" ? – Zardoz89 Nov 12 '18 at 06:46
  • Actually looks that I hit this old bug of m2e : https://bugs.eclipse.org/bugs/show_bug.cgi?id=397176 – Zardoz89 Nov 14 '18 at 08:37
  • I find a workaround to this. I set gulp to output a copy of the processed files to target/m2e-wtp/web-resources , so eclipse copy the resource files to the tomcat deploy. I would like an alternative to using maven-dependency to get the resources . I find very ugly setting gulp to copy the local resources over the dependency resources. – Zardoz89 Jan 15 '19 at 07:47