开发者

maven assembly throwing stackoverflowerror

开发者 https://www.devze.com 2023-04-03 17:01 出处:网络
Hi denizens of stackoverflow, I am having an issue with maven, specifically with the assembly phase. I have a large multi-module legacy project that unfortunately has some circular references within

Hi denizens of stackoverflow,

I am having an issue with maven, specifically with the assembly phase. I have a large multi-module legacy project that unfortunately has some circular references within its submodules. It has been retrofitted to build with maven, but to refactor the circular references out would take too long.

The proj开发者_运维百科ect builds fine by running mvn install, and even runs mvn package without issue, but fails when running mvn package assembly:assembly. Trying to run it with assembly:single gives me a build failure due to "Error creating assembly archive distrib: You must set at least one file".

With assembly:assembly, it seems to be processing the same libraries over and over again, eventually throwing a stackoverflowerror. I'm guessing this means that the circular references in the modules is causing this, though since it compiles with no issues, I had hope it would survive assembly as well.

Are there any other causes of this?

The structure of the project is as follows:

Parent
 |_ Child1
 |_ Child2
 |_ dist-proj

The parent pom has the following sections:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2.1</version>
    <configuration>
        <descriptors>
            <descriptor>src/main/assembly/assembly-dependencies.xml</descriptor>
        </descriptors>
    </configuration>
</plugin>
<modules>
    <module>Child1</module>
    <module>Child2</module>
    <module>dist-proj</module>
</modules>

The dist-proj pom:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2.1</version>
    <executions>
        <execution>
            <id>dist-proj</id>
            <phase>assembly</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <descriptors>
                    <descriptor>src/main/assembly/assembly-dependencies.xml</descriptor>
                </descriptors>
            </configuration>
        </execution>
    </executions>
</plugin>

And the assembly file:

<moduleSets>
    <moduleSet>
    <useAllReactorProjects>true</useAllReactorProjects>
    <includes>
        <include>groupid:Child1</include>
        <include>groupid:Child2</include>
     </includes>
          <binaries>
             <outputDirectory>${project.build.finalName}</outputDirectory>
             <unpack>false</unpack>
             <dependencySets>
                <dependencySet>
                   <includes/>
                   <scope>compile</scope>
                </dependencySet>
                <dependencySet>
                   <includes/>
                   <scope>runtime</scope>
                   <useTransitiveFiltering>true</useTransitiveFiltering>
                </dependencySet>
             </dependencySets>
       </binaries>
    </moduleSet>
</moduleSets>

Any help would be very much appreciated.


I have encountered this error as well. Looking at the Plexus Archiver source code, the hasNext method returned by getResources in AbstractArchiver calls itself every time it encounters a class or artifact it has already seen. This is causing it to run out of stack space even on medium size projects.

For now the easiest way to fix it is to increase your stack space via MAVEN_OPTS e.g.

export MAVEN_OPTS=-Xss2m

See http://jira.codehaus.org/browse/MASSEMBLY-549 for more details


To create only a jar which contains all dependencies you can simply use the predefined descriptor.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <descriptorRefs>
           <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
</plugin>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号