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

Maven projects do not have access to dependencies from the test scope #2569

Closed
clembo590 opened this issue Jul 15, 2022 · 7 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#2399 or #2878
Assignees
Labels

Comments

@clembo590
Copy link

Environment
  • Operating System: macos 12.0.1
  • JDK version: 1.8
  • Visual Studio Code version: 1.69.1
  • Java extension version: java extension pack v0.24.0
Steps To Reproduce

I have created a public repo so that the issue is easily reproducible:

step1: clone this repo:

git clone https://github.com/clembo590/issues.git --branch vs_code_does_not_build

step2: run mvn clean install
-->no issue

step 3: "import the project in vscode"
I get the error
The project was not built since its build path is incomplete. Cannot find the class file for org.slf4j.Logger. Fix the build path then try building this project
Screenshot 2022-07-15 at 16 24 48

@jdneo jdneo added the bug label Jul 18, 2022
@jdneo
Copy link
Collaborator

jdneo commented Jul 18, 2022

I can reproduce it. @snjeza is this related with the m2e migration?

@snjeza
Copy link
Contributor

snjeza commented Jul 18, 2022

I can reproduce the issue in the m2e 1.x . You can try the following patch:

diff --git a/pom.xml b/pom.xml
index 9067c56..c640ed3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,6 +10,7 @@
   <properties>
     <java.version>1.8</java.version>
     <feign.version>10.2.0</feign.version>
+    <m2e.disableTestClasspathFlag>true</m2e.disableTestClasspathFlag>
   </properties>
 
   <dependencies>

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=537578

@clembo590
Copy link
Author

@snjeza thank you for the suggestion and for the great work you guys are doing.
But does it feel OK to you that I would modify the code of my project in order for vscode to be able to work ?
To me this is not ok... Unfortunately I work for a big company where code is reviewed and we do not add code that should not be there.
Any plan on fixing this issue ? (I must say that I have been working in java in vscode for like 9 months and you guys are doing great but there are still some issues that really need to be fixed in order for java professionals to be able to use vscode instead of intellij. I posted several issues but it takes time to report those issues and if you decide to not fix it then I have wasted my time and yours.)

@snjeza
Copy link
Contributor

snjeza commented Aug 1, 2022

@clembo590 you can try the following:

  • create the usersettings.xml file
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <profiles>
        <profile>
            <id>m2e</id>
            <activation>
                <property>
                  <name>m2e.version</name>
                </property>
            </activation>
            <properties>
                <m2e.disableTestClasspathFlag>true</m2e.disableTestClasspathFlag>
            </properties>
        </profile>
    </profiles>
</settings>
  • add the following property to your settings.json
"java.configuration.maven.userSettings": "<path_to_usersettings.xml>",
  • reload your project

@clembo590
Copy link
Author

@snjeza thank you for this solution. (and sorry for the delay in the response: I got a baby and kind of was not focused on vscode anymore). Your solution: it does work indeed.

But Is there any plan to actually fix the issue so that a developper would not have to perform

  1. the creation of a maven user setting file specifcally for vscode....
  2. editing the settings.json file

The main problem I see here is that if a developpers has a "maven settings.xml" provided by a company with other profiles and mirrors etc... then you also have to put all those profiles/mirrors in the file you talked about...

Maybe instead of this:
Could we have a property called "disableTestClasspathFlag" that would be editable from vscode settings.json ?
Also why is this disableTestClasspathFlag property no set to true by default ? (I mean the example I posted is really the most basic thing a developper can create)

@snjeza
Copy link
Contributor

snjeza commented Jan 11, 2023

Also why is this disableTestClasspathFlag property no set to true by default ? (I mean the example I posted is really the most basic thing a developper can create)

It is an upstream m2e property

Could we have a property called "disableTestClasspathFlag" that would be editable from vscode settings.json ?

Yes, we could.
cc @fbricon @rgrunber

@rgrunber
Copy link
Member

rgrunber commented Jan 12, 2023

At the very least we should include a setting for this. I'm just wondering whether we can go as far as enabling it by default.

We might need to consider how Gradle projects behave and whether having a behaviour that might be different is desired.

@rgrunber rgrunber changed the title vscode refuses to build the simplest project Maven projects do not have access to dependencies from the test scope Jan 12, 2023
@snjeza snjeza self-assigned this Jan 12, 2023
@rgrunber rgrunber added this to the End February 2023 milestone Jan 19, 2023
tumbl3w33d added a commit to tumbl3w33d/nexus-oauth2-proxy-plugin that referenced this issue May 10, 2024
If you want to execute them in vscode java, you probably need to set java.import.maven.disableTestClasspathFlag to true. See redhat-developer/vscode-java#2569
tumbl3w33d added a commit to tumbl3w33d/nexus-oauth2-proxy-plugin that referenced this issue May 10, 2024
If you want to execute them in vscode java, you probably need to set java.import.maven.disableTestClasspathFlag to true. See redhat-developer/vscode-java#2569
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants