Search code examples
eclipsemaventycho

Eclipse JDT and Maven/Tycho do not agree on warnings


This is related to How to avoid Eclipse importing a class when putting the class name in the comments, so that checkstyle does not complain later?, but is a different issue.

I have a bunch of Javadoc references with import statements, as describe in the referenced question. Eclipse does not warn about this, but I still get compiler warnings when building my code with Maven/Tycho. I thought that specifying <compilerId>jdt</compilerId> should make Maven use the same compiler as Eclipse does, and there by generate identical sets of warnings.

I understand that I can use the fully qualified name in the Javadoc tag to avoid the import statement, but what I wonder here is how do I get the same set of compiler warnings when building with Maven/Tycho as when I build in Eclipse?


Solution

  • Tycho uses the JDT compiler by default, so you don't need to set the <compilerId>. However the compiler settings defaults may be different in Tycho and in Eclipse, or you may have changed the default settings in your workspace. You could try to configure the compiler in Tycho via the <compilerArgs> parameter to match your workspace settings, but this may get quite tricky.

    With Tycho 0.22.0 (cf. bug 404633) there is much easier way to get the exact same compiler settings in Eclipse and in Tycho:

    1. Enable project-specific Java compiler settings in Eclipse and configure them in the way you want them. This creates a file .settings/org.eclipse.jdt.core.prefs in the project.

    2. Add the following Maven configuration:

      <plugin>
         <groupId>org.eclipse.tycho</groupId>
         <artifactId>tycho-compiler-plugin</artifactId>
         <version>${tycho-version}</version>
         <configuration>
            <useProjectSettings>true</useProjectSettings>
         </configuration>
      </plugin>
      

    This makes the JDT compiler in Tycho use the Eclipse project settings whenever they are present.

    Note that you need to put the .settings/org.eclipse.jdt.core.prefs files under version control to make your build reproducible.