tags:

views:

110

answers:

2

I have one jar dependency in my java project that contains sources as well and when I run mvn compile, these java sources appear as class files in my compiled maven output :(... How can I exclude these files.. (I only want my own compiled files in the compiled output)

I tried something like:

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-compiler-plugin</artifactId>
 <version>2.1-SNAPSHOT</version>
 <configuration>
  <excludes>
    <exclude>**/bv/**/*.java</exclude>
   </excludes>
 </configuration>
</plugin>

Played with it but they keep appearing in my maven compiled output :( ..

Any idea's ?

+2  A: 

Would the provided scope work?

From: http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html:

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime.

Quotidian
No, because it's has to be packed finally in a war file, so I can't see how this work... Now I have the third party source classes packaged in my own jar as class files and the third party jar with his classes and source... :(... Doesn't sound very healty...
edbras
Let me see if I've got this right: Your jar has dependencies on a 3rd party jar, which also needs to be compiled. The 3rd party jar and your jar will then be included in the war...
Quotidian
+1  A: 

My understanding is that this is a normal behavior of javac that searches the whole classpath for source files to compile unless the -sourcepath option is given (and this would be the solution here).

Unfortunately, there is a Jira issue about -sourcepath not being passed to javac by the Maven Compiler Plugin (see MCOMPILER-98) but there is a workaround. So, could you please try this:

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <compilerArguments>
      <sourcepath>${project.basedir}/src/main/java</sourcepath>
    </compilerArguments>
  </configuration>
</plugin>
Pascal Thivent
Exactly, I also noticed the issue when trying to solve it...Did notice the workaround however.Thanks, I seems to work.. ;)
edbras