0

I am using maven with the scala-maven-plugin for building a project that is a mixture of Java 1.8 and Scala 2.12.7 code. When I build from the command line with:

mvn clean install -DskipTests

I get messages like:

"[WARNING] Could not determine source for class com.mycompany.MyClass_".

com.mycompany.MyClass is an annotated Java class that exists in my project. Note that the warning message has an underscore after "MyClass". There is no Java source code for a class named com.mycompany.MyClass_ in my project, but there is a class file at target/classes/com/mycompany/MyClass_.class.

What can I do to determine the cause of these warnings and remove them? (I can get rid of them by commenting out the scala-maven-plugin section of my pom file, but that seems a little extreme.)

Additional diagnostic data:

Following @Joachim Sauer's advice, I used javap to look at the class file. The output included:

Compiled from "MyClass_.java"

I did a search for "MyClass_.java" from the root of the project. It was found in

target/scoverage-classes/com/mycompany/MyClass_.java

When I look at that class in the editor, it includes:

@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(FileMetadata.class)

So it looks like the file generated by SCoverage and/or JPAMetaModelEntityProcessor is not locatable by some other tool. I'll dig some more...

kc2001
  • 5,008
  • 4
  • 51
  • 92
  • Where does these warnings appear? IDE? When running a command? – Gaël J Jan 09 '23 at 20:02
  • 3
    Can you create a minimal example showing the error you can share? – Thorbjørn Ravn Andersen Jan 09 '23 at 20:32
  • Do you have both classes `com.mycompany.MyClass` and `com.mycompany.MyClass_`? Do both of them have sources? Please show your `pom.xml`. If you're not sure about the classes please run `Class.forName("com.mycompany.MyClass").getResource("MyClass.class")`, `Class.forName("com.mycompany.MyClass_").getResource("MyClass_.class")` to see where these classes come from. Does your project use any code generation so that `MyClass_` can be auto generated? – Dmytro Mitin Jan 10 '23 at 02:07
  • Does your project use Java annotation processing? https://stackoverflow.com/questions/55558849/how-do-i-build-a-mixed-java-scala-project-which-uses-java-annotation-code-genera – Dmytro Mitin Jan 10 '23 at 02:10
  • @kc2001 I can see that you found that question too. – Dmytro Mitin Jan 10 '23 at 02:20
  • @DmytroMitin - I added answers to your questions to the problem description. – kc2001 Jan 10 '23 at 13:26
  • @ThorbjørnRavnAndersen - I'm trying to create a minimal example, but it's slow going. There are many inter-class dependencies, and it's difficult to know which part of the project to concentrate on. – kc2001 Jan 10 '23 at 13:28
  • @GaëlJ - I added my mvn command to the problem description. – kc2001 Jan 10 '23 at 13:29
  • 3
    *Something* seems to be generating this class and *something* (probably something other than the first something) is complaining about there being no source (which is weird, because few tools need access to the class *and* the source file). Your focus for the [mre] should be to identify the two somethings: Figure out which thing generates the weirdly-named class (maybe by inspecting it via `javap` to see what it contains) and what complains about it afterwards. – Joachim Sauer Jan 10 '23 at 13:29
  • 1
    @JoachimSauer - I followed your advice. Something-1 seems to be SCoverage. I'm still working on determining Something-2. I updated the question with the current findings. – kc2001 Jan 10 '23 at 14:08
  • @kc2001 Could you try to add additional source directory `target/scoverage-classes` (similarly to `Compile / unmanagedSourceDirectories += ...` in sbt)? https://stackoverflow.com/questions/9752972/how-to-add-an-extra-source-directory-for-maven-to-compile-and-include-in-the-bui https://stackoverflow.com/questions/270445/maven-compile-with-multiple-src-directories – Dmytro Mitin Jan 11 '23 at 03:22

0 Answers0