1

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

VeikkoW
  • 757
  • 6
  • 11

1 Answers1

3

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.

carlspring
  • 27,224
  • 23
  • 101
  • 178
  • Although this answer is useful regarding the wrong include format it does not help with the concrete question. The results using the include parameters are such that no source files are in the generated sources.jar, only the POM and META.INF – VeikkoW Sep 17 '14 at 11:28