0

I am migrating to Java 11 from Java 8. I am getting compile error when doing Maven build.

    src
       main
           com
              A.class
    
       test
          com
            Atest.class
 Atest.java {
  A a;//compile error

}

Have used plugin in pom.xml:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <executions>
                    <execution>
                        <id>default-compile</id>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

am getting error like:

[ERROR]   symbol:   class A
[ERROR]   location: class com.Atest
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile)
on project 'ourproject': Compilation failure

I have tried adding <release>11</release> ...but still getting same error. Anything do we need to add in pom file extra to compile for test classes?

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
shree
  • 2,745
  • 7
  • 28
  • 35

1 Answers1

0
  1. The standard directories for Java main and test classes are src/main/java and src/test/java, not just src/main and src/test, see Introduction to the Standard Directory Layout.
  1. In these dirs are Java source files (*.java) not compiled class files (*.class).

  2. Why declaring <executions> on the compiler plugin? See Configuring Your Compiler Plugin:

Since the Compiler Plugin executes automatically during their phases, you don't have to put executions unlike many other plugins.

  1. See Maven Surefire Plugin / Inclusions and Exclusions of Tests:

By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:

  • ...
  • "**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".

I'm not sure whether Atest.java is covered by this.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • Thanks for ur reply. i have tried the same...its not working in java 11...there is no issue with java 8. – shree Jul 15 '21 at 07:40