Issue
I'm facing some errors in my Maven project. My project structure is shown in the following image.
I define the class ProjectInfosDAO in the package main.resources.utils
and the others are in main.java.io.r2devops.jobSelector
.
ProjectInfos
class is called in JobSelector
class.
When I compile the project the following error is displayed:
cannot find symbol
symbol: variable ProjectDAO
location: class io.r2devops.jobSelector.JobSelector
Also the similar error occurs for the dependency Gson despite I mentionned it in pom.xml
and imported it in ProjectInfosDAO
.
cannot find symbol
symbol: variable Gson
location: class main.resources.utils.ProjectInfosDAO
In JobSelector
class:
import main.resources.ProjectInfosDAO;
public class JobSelector{
public static final void main(String[] args){
...
HashMap<String, TechnoInfos> technoInfos = ProjectInfosDAO.getTechnologiesInfos("technologies_infos.json");
...
}
}
In the pom.xml
:
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-bom</artifactId>
<type>pom</type>
<version>${drools-version}</version>
<scope>import</scope>
</dependency>
<!-- Gson: Java to JSON conversion -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
...
Thanks in advance for your kindly help.
Solution
Other than the problem mentioned by Roddy, the problem you have is with Maven. In Maven, <dependencyManagement>
is not used to define the dependencies of your project, but to define the versions and scope of them. This is normally useful in a multi-module project.
So, even if you have a <dependencyManagement>
in your pom.xml
, you still need to define the dependencies:
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-bom</artifactId>
<type>pom</type>
<version>${drools-version}</version>
<scope>import</scope>
</dependency>
<!-- Gson: Java to JSON conversion -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>
...
Or, if you are not in a multi-module project, you can probably get rid of the whole <dependencyManagement>
section:
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
<scope>compile</scope>
</dependency>
</dependencies>
Answered By - Esteban Aliverti
Answer Checked By - David Marino (JavaFixing Volunteer)