2

I have a Maven project using a war overlay. As outlined in this answer, one problem with WAR overlays is that they seem to effectively sidestep Maven's dependency resolution. This results in build and/or runtime verification errors.

Fortunately, there is a solution - using the overlay/excludes configuration directives. This ensures that the resultant WAR will only have what you want.

However, it seems that the jetty:run uses the war plugin's work directory for library resolution (which does contain the "bad" JAR).

The problem is avoided by using either jetty:run-war or jetty:run-exploded.

However,

  • as most of our projects run fine using jetty:run,
  • and jetty-run with scanInterval is very convenient during development,

I'd like to know whether it's possible to add some configuration changes to the POM that would force the run goal to use the target lib folder?


For illustration purposes, here's the specific example:

  • the project uses the org.apache.solr:solr:3.6.2 overlay,
  • the overlay includes an old version of Guava, r05, while our code uses a more recent one, 14.0.1,
  • as stated before, while the target artifact war is fine, jetty:run includes the r05 version into the classpath, which causes verification errors in our code.

Here's the example POM:

<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>solr.archetype.examination</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>A Solr project</name>

    <properties>
        <solr.version>3.6.2</solr.version>
        <solr.port>8983</solr.port>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr-core</artifactId>
            <version>${solr.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr</artifactId>
            <version>${solr.version}</version>
            <type>war</type>
        </dependency>

        <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr-solrj</artifactId>
            <version>${solr.version}</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>14.0.1</version>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <overlays>
                        <overlay>
                            <groupId>org.apache.solr</groupId>
                            <artifactId>solr</artifactId>
                            <excludes>
                                <exclude>**/guava-r05.jar</exclude>
                            </excludes> 
                        </overlay>
                    </overlays>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.25</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <stopKey>foo</stopKey>
                    <stopPort>9999</stopPort>
                    <contextPath>/solr</contextPath>
                    <connectors>
                        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                            <port>${solr.port}</port>
                            <maxIdleTime>60000</maxIdleTime>
                        </connector>
                    </connectors>
                    <systemProperties>
                        <systemProperty>
                            <name>solr.data.dir</name>
                            <value>target/data</value>
                        </systemProperty>
                    </systemProperties>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Community
  • 1
  • 1
mikołak
  • 9,605
  • 1
  • 48
  • 70

0 Answers0