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

VSCode Extension doesn't resolve auto value dependencies #193

Closed
plooploops opened this issue Dec 12, 2017 · 14 comments
Closed

VSCode Extension doesn't resolve auto value dependencies #193

plooploops opened this issue Dec 12, 2017 · 14 comments
Assignees
Labels
external needs more info voting Please vote on the issue, so that we will take priority to this issue.

Comments

@plooploops
Copy link

I'm building a project that utilizes com.google.auto.value.AutoValue to create builders which are placed in both the target folder and in the jar files. However, VSCode isn't picking these up either at run time and statically.

I believe the pom file is updated for the project as well so it should pick it up from the path.

Environment
  • Operating System: Windows 10
  • JDK version: 1.8
  • Visual Studio Code version: 1.18.1
  • Java extension version: 0.2.0
  • Java Debugger extension version: 0.4.0
Steps To Reproduce
  1. Import com.google.auto.value.AutoValue and apply the appropriate characteristics to the template class.
  2. Reference the auto value built class in a different class while also importing the com.google.auto.value.AutoValue dependency.
Current Result

The build doesn't pick up the dependency.

Expected Result

The build should pick it up at run time and statically.

Additional Information

vscode java

If we need to do a live chat, please let me know.

@fbricon
Copy link
Collaborator

fbricon commented Dec 12, 2017

autovalue is an annotation processor. Annotation Processors are not executed by vscode-java (see redhat-developer/vscode-java#339). If you're using Maven, you can try that solution as a workaround: redhat-developer/vscode-java#339 (comment)

@plooploops
Copy link
Author

I tried adding this update to the pom.xml as indicated in the link, but this looks like it’s having an issue still (based on the Maven suggestion).

This still leaves VSCode unable to resolve the auto generated sources, which sit in a different directory.

image
image
image

@fbricon
Copy link
Collaborator

fbricon commented Jan 22, 2018

Here are some instructions to get autovalue work in vscode-java: https://github.com/redhat-developer/vscode-java/wiki/Annotation-Processing-support-for-Maven-projects

@akaroml akaroml self-assigned this Mar 2, 2018
@akaroml
Copy link
Member

akaroml commented Mar 2, 2018

@plooploops can the instructions help address the issue?

@andxu
Copy link
Contributor

andxu commented Mar 15, 2018

It is not related to java debug, close it here, if the problem is not resolved, please recreate it on https://github.com/redhat-developer/vscode-java/issues

@andxu andxu closed this as completed Mar 15, 2018
@plooploops
Copy link
Author

plooploops commented Mar 15, 2018

Hi @andxu @akaroml @fbricon

Unfortunately it's still not quite picking up the dependencies for being able to run the Java debugger in VSCode.

What level of the pom do we want to place this in?
And when does this section get called, as part of the target bits are not yet in existence because of build order. Perhaps this is more a maven question but wanted to see your thoughts on it.
root
--examples/pom.xml refers to parts in SDK
--sdks/java/core/src has complaints as auto values are in target folder
--sdks/java/core/target not yet generated
pom.xml With current suggestions
This also indicates that VSCode is trying to resolve against the generated sources path, which is good. Not sure how to address the build order yet.

image

@andxu andxu reopened this Mar 16, 2018
@andxu
Copy link
Contributor

andxu commented Mar 16, 2018

Reopen it

@akaroml
Copy link
Member

akaroml commented Mar 19, 2018

@andxu any updates?

@andxu
Copy link
Contributor

andxu commented Mar 20, 2018

@plooploops Java debugger doesn't do anything special, it just uses the source and class path from Java Language Server(short jdt.ls at https://github.com/eclipse/eclipse.jdt.ls) to lunch your application and jdt.ls will use your pom xml for the project generation so make sure mvn package is able to run successfully, because the jdt.ls doesn't support auto-value now, mvn package is required to compile generated java files. I have tried to solution to Immutable values and succeed in debugging the code, see the gif, my project is listed below, please refer to my steps to see if this workaround could solve your problem, I will keep an eye on auto-value build feature in jdt.ls in the near future. 1

pom.xml

<?xml version="1.0" encoding="utf-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  <modelVersion>4.0.0</modelVersion>  
  <groupId>com.ms.samples</groupId>  
  <artifactId>simple-app</artifactId>  
  <version>1.0-SNAPSHOT</version>  
  <packaging>jar</packaging>  

  <name>simple-app</name>  
  <url>http://maven.apache.org</url>  
  <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
    <querydsl.version>4.0.1</querydsl.version>  
    <generatedSources>${project.build.directory}/generated-sources/java</generatedSources> 
  </properties>  
  <build> 
    <plugins> 
      <plugin> 
        <groupId>org.apache.maven.plugins</groupId>  
        <artifactId>maven-compiler-plugin</artifactId>  
        <version>3.7.0</version>  
        <configuration> 
          <!-- Need to disable default annotation processing since apt-maven-plugin takes over -->  
          <compilerArgument>-proc:none</compilerArgument> 
        </configuration> 
      </plugin>  
      <plugin> 
        <groupId>com.mysema.maven</groupId>  
        <artifactId>apt-maven-plugin</artifactId>  
        <version>1.1.3</version>  
        <executions> 
          <execution> 
            <goals> 
              <goal>process</goal> 
            </goals>  
            <configuration> 
              <outputDirectory>${generatedSources}</outputDirectory>  
              <processors> 
                <processor>org.immutables.processor.ProxyProcessor</processor> 
              </processors> 
            </configuration> 
          </execution> 
        </executions> 
      </plugin>  
      <plugin> 
        <groupId>org.codehaus.mojo</groupId>  
        <artifactId>build-helper-maven-plugin</artifactId>  
        <version>3.0.0</version>  
        <executions> 
          <execution> 
            <!-- Need to ensure the generated source folder is added to the project classpath, in jdt.ls -->  
            <id>add-source</id>  
            <phase>generate-sources</phase>  
            <goals> 
              <goal>add-source</goal> 
            </goals>  
            <configuration> 
              <sources> 
                <source>${generatedSources}</source> 
              </sources> 
            </configuration> 
          </execution> 
        </executions> 
      </plugin> 
    </plugins> 
  </build>  
  <dependencies> 
    <dependency> 
      <groupId>com.google.guava</groupId>  
      <artifactId>guava</artifactId>  
      <version>24.1-jre</version> 
    </dependency>  
    <!-- https://mvnrepository.com/artifact/org.immutables/value-processor -->  
    <dependency> 
      <groupId>org.immutables</groupId>  
      <artifactId>value-processor</artifactId>  
      <version>2.5.6</version>  
      <scope>test</scope> 
    </dependency>  
    <dependency> 
      <groupId>org.immutables</groupId>  
      <artifactId>value</artifactId>  
      <version>2.5.5</version>  
      <scope>provided</scope> 
    </dependency>  
    <dependency> 
      <groupId>com.google.auto.value</groupId>  
      <artifactId>auto-value</artifactId>  
      <version>1.5.3</version> 
    </dependency>  
    <dependency> 
      <groupId>junit</groupId>  
      <artifactId>junit</artifactId>  
      <version>3.8.1</version>  
      <scope>test</scope> 
    </dependency> 
  </dependencies> 
</project>

FoobarValue.java

package com.ms.samples;

import java.util.List;
import java.util.Set;
import org.immutables.value.Value;

@Value.Immutable
interface ValueInterface {
  
}

@Value.Immutable
public abstract class FoobarValue {
  public abstract int foo();
  public abstract String bar();
  public abstract List<Integer> buz();
  public abstract Set<Long> crux();
}

App.java

package com.ms.samples;

import java.util.List;
/**
 * Hello world!
 *
 */
public class App {
    public static void main(String[] args) {
        
        FoobarValue value = ImmutableFoobarValue.builder()
            .foo(2)
            .bar("Bar")
            .addBuz(1, 3, 4)
            .build(); // FoobarValue{foo=2, bar=Bar, buz=[1, 3, 4], crux={}}

         int foo = value.foo(); // 2

         List<Integer> buz = value.buz(); // ImmutableList.of(1, 3, 4)
    }
}

launch.json

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "java",
      "name": "Debug (Launch)-App<simple-app>",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "mainClass": "com.ms.samples.App",
      "projectName": "simple-app",
      "args": ""
    },
    {
      "type": "java",
      "name": "Debug (Attach)",
      "request": "attach",
      "hostName": "localhost",
      "port": 0
    }
  ]
}

@plooploops
Copy link
Author

@andxu Thanks. I'll see if I can adapt this work around with mvn package.

When do we expect jdt.ls to support auto-values?

@andxu
Copy link
Contributor

andxu commented Mar 21, 2018

I will work on jdt.ls on project support in next sprint, I can hardly give you the timeline, but will update the progress in this issue.

@yaohaizh
Copy link
Contributor

yaohaizh commented Jun 20, 2018

@andxu: laguage server already support this one, please verify this:
https://github.com/eclipse/eclipse.jdt.ls/pull/616/files

@andxu andxu added the voting Please vote on the issue, so that we will take priority to this issue. label Jun 20, 2018
@andxu
Copy link
Contributor

andxu commented Jun 20, 2018

I have verified on latest java language support 0.27.0 on auto-value, it now supports the compilation of auto-value, then you are not required to run mvn package manually, please take a try @plooploops.
image

image

@yaohaizh
Copy link
Contributor

Close this one as been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external needs more info voting Please vote on the issue, so that we will take priority to this issue.
Projects
None yet
Development

No branches or pull requests

5 participants