Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

350
Visualizações
Compilation failure: "cannot find symbol" when applying module-info.java in multi module Maven project?

Please disregard this question. For unknown reasons, the project started working when I took a second look at it. After reading this page in the Stack Overflow question I opt to Close it (instead of Deleting it).


How can I get test dependencies to work in a multi module maven project when using Java 9 modules?

Given that I have the following project structure:

+ pom.xml
|
+ first
|  + pom.xml
|  + src/main/java/
|               + module-info.java
|               + com/example/first/First.java
|
+ second
|  + pom.xml
|  + src/main/java/
|               + module-info.java
|               + com/example/second/Second.java
|  + src/test/java/
|               + com/example/second/SecondTest.java

First module

The module-info.java file in the first project looks like this:

module com.example.first {
    exports com.example.first;
}

and the corresponding pom.xml file:

<artifactId>first</artifactId>
<groupId>com.example</groupId>

Second module

I would like that the second module should have a test dependency on the first module. For this reason I have attempted the following configuration.

module-info.java file in the second project:

module com.example.second {
    exports com.example.second;
}

pom.xml file:

<artifactId>second</artifactId>
<groupId>com.example</groupId>
<dependencies>
    <dependency>
        <artifactId>first</artifactId>
        <groupId>com.example</groupId>
        <scope>test</test>
    </dependency>
</dependencies>

And the SecondTest.java file includes First as a dependency:

package com.example.second;

import com.example.first.First;

public class SecondTest {
    First first;
    Second second;

    // setup and test methods...
}

Problem

With the configuration above, the test compilation fails:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project second: Compilation failure: Compilation failure: 
[ERROR] [...]/src/com/example/SecondTest.java: cannot find symbol
[ERROR]   symbol:   class First
[ERROR]   location: package com.example.first

Workaround

I could change the scope of the com.example.first in the pom.xml file of the to compile and add requires com.example.first in the module-info.java file in the second module and the test compilation would work. However, that would also imply that the second module would depend on first when it is being used elsewhere and that is not desired.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Do:

module com.example.second {
   requires com.example.first;
}

... (additionally) in second/src/test/java!

Whereas in second/src/main/java, we can keep it as:

module com.example.second {
    exports com.example.second;
}

as in (second) pom (only):

<dependency>
  <groupId>com.example</groupId>
  <artifactId>first</artifactId>
  <scope>test</test>
</dependency>

For modules to work we need maven-compiler-plugin >= 3.6!

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda