How to keep the maven structure when creating source-jar

1k Views Asked by At

I am using the maven-source-plugin to pack the sources of the project. Normally you get all from the main/java and main/resources packed together into one root.

What I want is to keep the project structure in the final -source.jar - like src/main/java/**, src/main/resources/** and the test part too.

I tried the includes configuration which did not help

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
        <id>attach-sources</id>
        <goals>
            <goal>jar-no-fork</goal>
        </goals>
            <configuration>
                <includes>src/main/**, src/resources/**</includes>
            </configuration>
        </execution>
    </executions>
</plugin>

The error I get is

[INFO] Failed to configure plugin parameters for: org.apache.maven.plugins:maven-source-plugin:2.3

(found static expression: 'src/main/**, src/resources/**' which may act as a default value).

Cause: Cannot assign configuration entry 'includes' to 'class [Ljava.lang.String;' from 'src/main/**, src/resources/**', which is of type class java.lang.String

Is it really the "found static expression" error or is the configuration no correct? Or is there another way to achieve this?


Edit

So when changing the POM as in the hint from @carlspring the error is gone, but the result is that neither source nor resource files are in the resulting sources.jar

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <id>attach-sources</id>
            <goals>
                <goal>jar-no-fork</goal>
            </goals>
            <configuration>
        <includes>
        <include>src/main/**</include>
        <include>src/test/**</include>
        </includes>
            </configuration>
        </execution>
    </executions>
</plugin>

Maybe the clue is in the description of the includes option:

List of files to include. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.

Which means if the input directory for jar-no-fork is src/main/java|resources then my question must be answered NO WAY

1

There are 1 best solutions below

1
On

You are using the <includes/> incorrectly. This is not a comma-separated list. Each entry should be defined as it's own <include/>. Try it like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
        <id>attach-sources</id>
        <goals>
            <goal>jar-no-fork</goal>
        </goals>
            <configuration>
                <includes>
                    <include>src/main/**</include>
                    <include>src/resources/**</include>
                </includes>
            </configuration>
        </execution>
    </executions>
</plugin>

Furthermore, I would actually recommend you use the maven-assembly-plugin instead and create the sources with it, as it would be much easier, in my opinion. Have a look here.