maven sources plugin includes configuration

4.4k Views Asked by At

I have a maven project with a non standard configuration:

$> tree                                                                                          
.
├── pom.xml
├── symbolic-link-to-sources -> ../src
└── target
    ├── maven-archiver
    │   └── pom.properties
    ├── project-1.0-SNAPSHOT-sources.jar
    ├── project-1.0-SNAPSHOT.jar
    └── surefire

I am trying to generate the sources jar of this maven module, whose sources are in ../src. I created a symbolic link to ../src in the case the plugin does not accept parent folders in paths. To do so I use the maven source plugin configured like this:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <version>2.2.1</version>
  <configuration>
    <includePom>true</includePom>
    <includes>
      <include>symbolic-link-to-sources/**</include>
    </includes>
  </configuration>
</plugin>

I run this plugin with mvn source:jar. Unfortunately I get only pom.xml in my sources jar. If I set includePom to false the plugin does not create the source archive.

I tried a lot of things as <include>: ../src, ../src/**, ../**, symbolic-link-to-sources, symbolic-link-to-sources/**, ../**/*.java none of them get me my sources into my sources jar. Although the documentation about it say its a relative fileset pattern.

Any idea how to get the content the java files of the ../src folder into my sources jar?

(Yes my symbolic link is not broken, no there is no way to rearrange my modules to have a standard folder hierarchy, this is a wrapper project around an ant based project).

2

There are 2 best solutions below

0
On

You would use the <includes property to specify files/patterns to include within the source folder.

Have you set <sourceDirectory> to the correct location of the source (symbolic link and so on)? If so, can you omit the entire plugin configuration above and just run mvn source:jar on the pom? It should generate the sources correctly.

0
On

Stuck with the same problem and after googling and trying finally came to this:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>add-source</goal>
      </goals>
      <configuration>
        <sources>
          <source>../common/src/main/java</source>
        </sources>
      </configuration>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <executions>
    <execution>
      <id>attach-sources</id>
      <goals>
        <goal>jar</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Where "../common/src/main/java" is a path to sources that are linked as symbolic link in the current project.

Please note that build-helper-maven-plugin has package phase. With phase generate-sources I was getting "duplicate class" since the same sources were added from the symbolic link dir and from the dir configured in build-helper-maven-plugin.