0

I am running eclipse oxygen (release 4.7.3a) with maven plugin m2e (1.8.3.20180227) and java 8 (jdk1.8.0_172)

Updated eclipse to Version: 2019-03 (4.11.0), m2e 1.11.0.20190220-2119, java version unchanged. Same behavior persists.

I have a project with a module. The module has /src/main/java and src/test/java The junit dependency is test scope.

When I run maven install I get errors during compile

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project something: Compilation failure: Compilation failure:

[ERROR] /C:/Users/me/git/base/module/src/test/java/com/company/redacted/db/IsAdminQueryTest.java:[3,24] package org.junit does not exist

If I change the scope of junit to default it compiles and runs fine.

A perhaps related symptom If I run Maven -> Update Project, I get an error:

Cannot nest 'module/src/main/resources' inside 'module/src/'. To enable nesting exclude 'main/' from 'module/src/'

However module/src is not a java source folder.

from the maven log during the compile stage when running with -e -X.

Note the test in the path

[DEBUG] Stale source detected: C:\Users\me\git\base\module\src\main\java\com\company\redacted\db\IsAdminQuery.java

[DEBUG] Stale source detected: C:\Users\ms\git\base\module\src\test\java\com\company\redacted\db\IsAdminQueryTest.java

Where should I look for the bad config?

Update after upgrade I had changed the scope of junit and mockito to global to work around this problem. When I changed them back to scope: test the test case started having dependency issues/failure to compile. Clearly eclipse/maven doesn't know my test classes are test classes.

I have installed maven directly on my pc. Running mvn install from the command line has the same issues as running in eclipse.

Aaron
  • 874
  • 3
  • 17
  • 34

2 Answers2

1

I was something of an idiot. I am not sure how it happened (copy paste error perhaps) but I had set the source directory in the build section of my pom.xml. Removing that solved all my problems.

Thanks to all who made suggestions especially @Sambit.

  <build>
    **<sourceDirectory>src</sourceDirectory>**
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
Aaron
  • 874
  • 3
  • 17
  • 34
0

You can follow the steps in case of maven project.

  • In a maven based project, before configuring the project, go to command prompt and run either mvn clean install or mven clean package.
  • In case of Eclipse,I will suggest to use latest version of Eclipse. For existing maven project, use as Import Maven project in Eclipse. You have to go to File Menu > Import > Existing Maven project.
  • Project in eclipse may take sometime depending upon the number of dependencies. After sometime, you have to click ALT+F5 by selecting the project.
Sambit
  • 7,625
  • 7
  • 34
  • 65