开发者

how to exclude java sources from a third party jar?

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>
 <g开发者_如何学JAVAroupId>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 ?


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>


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.


You can pass the -implicit:none parameter to the compiler

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <compilerArgument>-implicit:none</compilerArgument>
    </configuration>
  </plugin>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜