Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with Micronaut and Visual Studio Code with Java #693

Closed
graemerocher opened this issue Oct 29, 2018 · 21 comments
Closed

Issues with Micronaut and Visual Studio Code with Java #693

graemerocher opened this issue Oct 29, 2018 · 21 comments

Comments

@graemerocher
Copy link

I had a chat with @fbricon at CodeOne and we got the basics of Micronaut working with Code however there are a couple of areas that I can't seem to get to work.

  1. Gradle support doesn't seem to work at all, the annotation processors are simply not applied.
  2. Maven support partially works. Annotation processors are applied to sources in src/main/java, but tests don't work because the processors are not applied to src/test/java.
Environment
  • Operating System: OS X
  • JDK version: Java 8 or 11
  • Visual Studio Code version: 1.28.2 (1.28.2)
  • Java extension version: Extension Package 0.4.0
Steps To Reproduce for Gradle
  1. Clone the repo https://github.com/micronaut-projects/micronaut-examples
  2. cd hello-world-java
  3. Run gradle eclipse
  4. Run code .
Current Result

The application can be run but if you hit http://localhost:8080/hello/john you receive a 404 and although the tests pass they pass because the test is skipped because it isn't configure as a bean.

Expected Result

The test should not be skipped and http://localhost:8080/hello/john should not 404

Steps To Reproduce for Maven
  1. Clone the repo https://github.com/micronaut-projects/micronaut-examples
  2. cd hello-world-java
  3. Remove the build.gradle (so that VSC uses the pom.xml)
  4. Run code .
Current Result

The result is better than with Gradle, the application can be run and if you hit http://localhost:8080/hello/john you get the right result. This means the annotation processors are applied to src/main/java.

However if you run a test the test is skipped because the annotation processor are not applied. If you however run ./mvnw test the test is not skipped because the processors are applied

Expected Result

The test should not be skipped because annotation processors should be applied to test sources.

@fbricon
Copy link
Collaborator

fbricon commented Oct 29, 2018

so we should see extra class files automatically generated in the test ouput directory?

@graemerocher
Copy link
Author

Yes that is correct

@fbricon
Copy link
Collaborator

fbricon commented Oct 29, 2018

Ok so the gradle integration, I need to look at separately, because the eclipse/buildship/gradle combo does its own thing and I'm not too familiar with gradle.

As for the Maven integration, I was able to reproduce the same behavior in Eclipse, where no extra test classes were generated under target/test-classes, when you import the project.
But, if you make a change to src/test/java/example/HelloClient.java, AP kicks in, those test classes appear. Same thing in vscode. So I suspect something's fishy in JDT APT. cc @brychcy.

The next problem is, when running HelloControllerTest, the test is still skipped. No idea why for now.

@fbricon
Copy link
Collaborator

fbricon commented Oct 29, 2018

@graemerocher skipped test is a micronaut issue. Fresh clone of the project then
cd hello-world-java; ./mvnw clean verify gets you:

[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hello-world ---
[INFO] Surefire report directory: /Users/fbricon/Dev/souk/micronaut-examples/hello-world-java/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running example.HelloControllerTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

@graemerocher
Copy link
Author

@fbricon yeah it looks like Maven is not applying the annotation processors to the test source code the same was as Gradle. I am investigating the issue

@fbricon
Copy link
Collaborator

fbricon commented Oct 30, 2018

Chances are, once the problem with Maven skipping the tests is fixed, it'll also work in Eclipse, then in VS Code

@graemerocher
Copy link
Author

I pushed some changes to the pom.xml that resolves the issue with ./mvnw clean verify however I am still seeing the issue with test being skipped in VSC

@brychcy
Copy link

brychcy commented Nov 5, 2018

I cannot reproduce the problem in eclipse (using the master of jdt, m2e and m2e-apt), but maybe because of the pom.xml changes.

@snjeza
Copy link
Contributor

snjeza commented Nov 7, 2018

@fbricon @graemerocher Could you try to add the following dependency:

<dependency>
	<groupId>io.micronaut.test</groupId>
	<artifactId>micronaut-test-spock</artifactId>
	<version>1.0.0.RC1</version>
	<scope>test</scope>
</dependency>

@fbricon
Copy link
Collaborator

fbricon commented Nov 16, 2018

Yeah I confirm adding the micronaut-test-spock dependency immediately triggers proper generation of test byte code. Without even touching the .factorypath. Since most of the dependencies are groovy stuff, I thought adding junit:4.12 to the dependencies instead would do the trick, but no dice. There's something fishy here, related to spock. @snjeza any idea why? How did you find out about spock?

@fbricon
Copy link
Collaborator

fbricon commented Nov 16, 2018

@brychcy I get the exact same behavior in Eclipse 2018-12 M2

@snjeza
Copy link
Contributor

snjeza commented Nov 16, 2018

How did you find out about spock?

I have reviewed the log and noticed that io.micronaut.test.extensions.spock.MicronautSpockExtension is missing.

@fbricon
Copy link
Collaborator

fbricon commented Nov 16, 2018

Wow, I don't know how I missed that 🤦‍♂️

Caused by: org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type io.micronaut.test.extensions.spock.MicronautSpockExtension cannot be resolved. It is indirectly referenced from required .class files
	at org.eclipse.jdt.internal.compiler.problem.ProblemHandler.handle(ProblemHandler.java:162)
	at org.eclipse.jdt.internal.compiler.problem.ProblemHandler.handle(ProblemHandler.java:229)
	at org.eclipse.jdt.internal.compiler.problem.ProblemReporter.handle(ProblemReporter.java:2550)
	at org.eclipse.jdt.internal.compiler.problem.ProblemReporter.isClassPathCorrect(ProblemReporter.java:5005)
	at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:123)
	at org.eclipse.jdt.internal.compiler.lookup.UnresolvedAnnotationBinding.getElementValuePairs(UnresolvedAnnotationBinding.java:62)
	at org.eclipse.jdt.internal.compiler.apt.model.AnnotationMirrorImpl.getElementValues(AnnotationMirrorImpl.java:119)
	at io.micronaut.annotation.processing.JavaAnnotationMetadataBuilder.readAnnotationRawValues(JavaAnnotationMetadataBuilder.java:198)
	at io.micronaut.annotation.processing.JavaAnnotationMetadataBuilder.readAnnotationRawValues(JavaAnnotationMetadataBuilder.java:55)
	at io.micronaut.inject.annotation.AbstractAnnotationMetadataBuilder.populateAnnotationData(AbstractAnnotationMetadataBuilder.java:283)
	at io.micronaut.inject.annotation.AbstractAnnotationMetadataBuilder.buildStereotypeHierarchy(AbstractAnnotationMetadataBuilder.java:535)
	at io.micronaut.inject.annotation.AbstractAnnotationMetadataBuilder.processAnnotationStereotype(AbstractAnnotationMetadataBuilder.java:567)
	at io.micronaut.inject.annotation.AbstractAnnotationMetadataBuilder.buildInternal(AbstractAnnotationMetadataBuilder.java:508)
	at io.micronaut.inject.annotation.AbstractAnnotationMetadataBuilder.build(AbstractAnnotationMetadataBuilder.java:86)
	at io.micronaut.annotation.processing.AnnotationUtils.getAnnotationMetadata(AnnotationUtils.java:125)
	at io.micronaut.annotation.processing.visitor.LoadedVisitor.matches(LoadedVisitor.java:94)
	at io.micronaut.annotation.processing.TypeElementVisitorProcessor.lambda$null$1(TypeElementVisitorProcessor.java:133)
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174)
	at java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1625)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
	at io.micronaut.annotation.processing.TypeElementVisitorProcessor.lambda$process$2(TypeElementVisitorProcessor.java:133)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
	at java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1553)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
	at io.micronaut.annotation.processing.TypeElementVisitorProcessor.process(TypeElementVisitorProcessor.java:131)
	at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:142)
	... 24 more

@graemerocher does it make sense? I need to figure out why Maven CLI adds it to the classpath, but it is ignored in m2e

@graemerocher
Copy link
Author

@fbricon It does make sense. Note however the missing Spock dependency is by design. We support Spock and Junit 5 with only one needing to be on the class path

Although the annotation does reference a class that is not there. This is not an issue with javac nor an issue with Spock or Junit at runtime

I don’t want users to have to use 2 different annotations for each framework so what we will probably do is try and catch the exception in our annotation processors

However to me this is a bug in the Eclipse APT support as it behaves differently to javac and runtime Java

@graemerocher
Copy link
Author

I filed https://bugs.eclipse.org/bugs/show_bug.cgi?id=541466 to track this issue in the Eclipse APT implementation

@fbricon
Copy link
Collaborator

fbricon commented Dec 18, 2018

@graemerocher when's the next release of micronaut-inject containing the fix?

@graemerocher
Copy link
Author

@fbricon Either today or tomorrow, just wrapping up the last few issues

@fbricon
Copy link
Collaborator

fbricon commented Jan 8, 2019

Maven flavour of helloworld-java now works OOTB (once you set <micronaut.version>1.0.2</micronaut.version>)

To get JDT APT support for Gradle projects, you need explicit .factorypath, .settings/org.eclipse.jdt.apt.core.prefs, .settings/org.eclipse.jdt.core.prefs manipulation in the build.gradle file. The process is documented here.

@graemerocher
Copy link
Author

Yes it does, closing this now. Thanks!

@fbricon
Copy link
Collaborator

fbricon commented Jan 8, 2019

FTR, providing OOTB annotation processing support for Gradle requires Gradle/Buildship to be enhanced. Go vote for it.

@ecmel
Copy link

ecmel commented Oct 12, 2020

Annotation processing for Micronaut maven projects is not working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants