Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: The type cannot be resolved. It is indirectly referenced from required .class files

Tags:

maven

maven-3

I changed some existing projects from ant to maven projects. So far so good.

All projects do have the same groupId. Theres a project with name "ServerBase" and artifactId "server-base". Within this project theres an abstract class "BaseService" which defines a logger via:

import org.jboss.logging.Logger;
[...]
protected Logger log = Logger.getLogger(this.getClass());

Theres another project with name "Server" and artifactId "server". Within this project theres a class ConfigurationDAOImpl extending the BaseService-Class above. Within ConfigurationDAOImpl the logger log is used for creating some outputs.

Within the "Server"'s POM file I have declared:

    <dependency>
        <groupId>com.tcom.amadeus</groupId>
        <artifactId>server-base</artifactId>
        <version>${project.version}</version>
    </dependency>

Under BuildPath the dependency is shown very nice under MavenDependencies. I removed the old dirct/natural/ant-dependency from build path before. If I remove it I am getting very much errors about missing classes etc. But although I do have this dependency I am getting the followin error in eclipse (under tab markers):

The type org.apache.commons.logging.Log cannot be resolved. It is indirectly referenced from required .class files

Resource: ConfigurationDAPImpl.java

Path: /Server/src/main/...

Location: Line 24

Type: Java Problem

I tried removing the dependency and add it again but without any luck. Both projects do refer to JAVA 1.8. Both projects have been build with targets clean an package multiple times. Both projects have been updated by Righclick or pressing F5. I am using Eclipse Version: Neon.1a Release (4.6.1) I am using apache-maven-3.3.9 I am using m2e Plugin.

Any further help would be grateful. Thanks in advance.

like image 601
Kaspatoo Avatar asked Feb 08 '17 16:02

Kaspatoo


Video Answer


1 Answers

There are two ways to 'solve' this:

1) explicitly add the required dependency within the server-projects pom-file:

<dependency>
  <groupId>org.jboss.logging</groupId>
  <artifactId>jboss-logging</artifactId>
</dependency>

2) change the scop of the required dependency within the server-base-projects pom file from up to now 'provide' to 'compile' or erase the scope tag at all such that the default scope is used by maven (which I guess is 'compile')

old:

<dependency>
  <groupId>org.jboss.logging</groupId>
  <artifactId>jboss-logging</artifactId>
  <scope>provided</scope>
</dependency>

new:

<dependency>
  <groupId>org.jboss.logging</groupId>
  <artifactId>jboss-logging</artifactId>
  <scope></scope>
</dependency>

or:

<dependency>
  <groupId>org.jboss.logging</groupId>
  <artifactId>jboss-logging</artifactId>
</dependency>

Some background to this from documentation:

http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Transitive_Dependencies

provided This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

Thanks all.

like image 163
Kaspatoo Avatar answered Sep 18 '22 12:09

Kaspatoo