Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven-compiler-plugin 3.0 not compiling resources folder under maven

I'm porting a project form Maven 2 to Maven 3. I've taken the opportunity to also update the version of some plugins, namely maven-compiler-plugin, from 2.1 to 3.0, and maven-resources-plugin, to 2.6.

I have an interface under resources as such:

public interface Version {
  public static final String VERSION = "${project.version}";
}

And in my pom.xml, under build, I have:

<resources>
  <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
  </resource>
</resources>

This was previously working. But since the upgrade to Maven 3, compilation fails with not being able to find Version.

It seems obvious that it's not compiling Version or not including it in the classpath.

Is there some change with Maven 3 or latest versions of maven-compiler-plugin that might affect this? From reading the documentation nothing changed...

like image 997
halfwarp Avatar asked Jan 31 '26 11:01

halfwarp


1 Answers

You have to specify the target folder to something like below. Currently if you look in your target folder you probably have a Version.java file in there. By adding the targetPath it will put the filtered .java file into your src/java folder and will compile it to your target folder.

<resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
     <includes>
       <include>**/*.java</include>
    </includes>
    <targetPath>${basedir}/src/main/java/</targetPath>
</resource>
like image 187
Manuel Quinones Avatar answered Feb 02 '26 01:02

Manuel Quinones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!