[maven-2] maven compilation failure

I have a weird problem - Some class file couldn't be read during maven build.

  1. I have a project A and project B.
  2. Project B depends on the project A target JAR file.

During the project B compilation it is not able to read lib in the project A JAR file - though the part directed to it is perfect.

I have also checked and verified the maven script and it is perfect.

Error:

[INFO] Compiling 137 source files to V:\dhs_tss_build_view\dhs_tssproject\tss\tsscommon-server\target\classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure

V:/dhs_tss_build_view/dhs_tssproject/tss/tsscommon-server/src/main/java/us/mn/state/dhs/tss/common/oblix/da/wsdl/OblixLoginAc
cess.java:[51,60] cannot find symbol
symbol  : class BusinessException
location: class us.mn.state.dhs.tss.common.oblix.da.wsdl.OblixLoginAccess

V:/dhs_tss_build_view/dhs_tssproject/tss/tsscommon-server/src/main/java/us/mn/state/dhs/tss/common/app/da/ldap/BaseLdapImpl.j
ava:[187,14] cannot find symbol
symbol  : class Phone
location: class us.mn.state.dhs.tss.common.app.da.ldap.BaseLdapImpl

V:/dhs_tss_build_view/dhs_tssproject/tss/tsscommon-server/src/main/java/us/mn/state/dhs/tss/common/app/da/ldap/BaseLdapImpl.j
ava:[204,14] cannot find symbol
symbol  : class Phone
location: class us.mn.state.dhs.tss.common.app.da.ldap.BaseLdapImpl


[INFO] ------------------------------------------------------------------------
[DEBUG] Trace
org.apache.maven.BuildFailureException: Compilation failure
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:579)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:499)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:478)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330
)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure
        at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:516)
        at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
        ... 16 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 56 seconds
[INFO] Finished at: Mon Oct 19 09:46:53 CDT 2009
[INFO] Final Memory: 11M/20M
[INFO] ------------------------------------------------------------------------

This question is related to maven-2

The answer is


My guess is a wrong version of project A jar in your local maven repository. It seems that the dependency is resolved otherwise I think maven does not start compiling but usually these compiling error means that you have a version mix up. try to make a maven clean install of your project A and see if it changes something for the project B... Also a little more information on your setting could be useful:

  • How is maven launched? what command? on a shell, an IDE (using a plugin or not), on a CI server?
  • What maven command are you using?

I had the same issue (even though the project was compiling/working fine in Eclipse), it was not when using the command line build. The reason was that I wasn't using the correct folder structure for mvn: "src/main/java/com" etc. It is looking at these folders by default (I was using "/scr/main/com" etc. which caused issues).


I had a similar problem, and never find anything on the web after excessive searching.

I reviewed the pom.xml file and in the dependencies I changed the scope of the <dependency> it: <scope>test</scope> to <scope>compile</scope> .

Previously I was using it only for tests but I change the project's structure and never knew I hve to change this.

test: This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.

compile: This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.

Here is a reference from Apache Maven Docs: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope


After running following command:- mvn clean package install

I found the issue:
'dependencies.dependency.scope' for org.springframework.boot:spring-boot-starter-data-rest:pom must be one of [provided, compile, runtime, test, system] but is 'import'. @ line 13, column 11

One of the dependency was marked as 'import'. Changing the 'scope' solved the issue for me.


The error is pretty clear: "cannot find symbol". Some dependencies can't be resolved (you even have the line and column in the trace of the reference that can't be resolved):

V:/dhs_tss_build_view/dhs_tssproject/tss/tsscommon-server/src/main/java/us/mn/state/dhs/tss/common/oblix/da/wsdl/OblixLoginAc
cess.java:[51,60] cannot find symbol
symbol  : class BusinessException
location: class us.mn.state.dhs.tss.common.oblix.da.wsdl.OblixLoginAccess

V:/dhs_tss_build_view/dhs_tssproject/tss/tsscommon-server/src/main/java/us/mn/state/dhs/tss/common/app/da/ldap/BaseLdapImpl.j
ava:[187,14] cannot find symbol
symbol  : class Phone
location: class us.mn.state.dhs.tss.common.app.da.ldap.BaseLdapImpl

V:/dhs_tss_build_view/dhs_tssproject/tss/tsscommon-server/src/main/java/us/mn/state/dhs/tss/common/app/da/ldap/BaseLdapImpl.j
ava:[204,14] cannot find symbol
symbol  : class Phone
location: class us.mn.state.dhs.tss.common.app.da.ldap.BaseLdapImpl

Below a couple of things to verify:

  • Check or recheck that these classes are in the jar A (same version as in the pom)
  • Check or recheck the import statement in B sources (should match the package of classes in A)
  • Check or recheck B's pom.xml and especially the declaration of the dependency on A (it's version)
  • Check that the dependency on A is not excluded transitively somewhere in B's pom
  • Is A a SNAPSHOT dependency? If no, delete A from your local repository and rebuild

Maven is working fine, you have a mistake somewhere.


Inside in yours classses on which is complain maven is some dependecy which belongs to some jar's try right these jars re-build with maven command, i use this command mvn clean install -DskipTests=true should be work in this case when some symbols from classes is missing


I had the same problem and this is how I suggest you fix it:

Run:

mvn dependency:list

and read carefully if there are any warning messages indicating that for some dependencies there will be no transitive dependencies available.

If yes, re-run it with -X flag:

mvn dependency:list -X

to see detailed info what is maven complaining about (there might be a lot of output for -X flag)

In my case there was a problem in dependent maven module pom.xml - with managed dependency. Although there was a version for the managed dependency defined in parent pom, Maven was unable to resolve it and was complaining about missing version in the dependent pom.xml

So I just configured the missing version and the problem disappeared.


I had the same problem...

How to fix - add the following properties in to the pom.xml

<properties>
    <!--  compiler settings -->
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
</properties>        

It's easy to get this error in a multi-module project. If, for example, you made changes to modules A, B, and C, but then you try to compile just module B, you are susceptible to this error. Say module B has a dependency on module A. Since only module B was compiled, the class files from module A are now out of date and possibly invalid.

Compiling all the modules (or modules in the proper hierarchical dependency order) resolves this error, if this is the nature of your problem.


If your dependencies are fine (check with mvn dependency:list) like mine were, then it's a maven glitch, if you're using Eclipse do:

  1. Right click the project > Maven > Update Project...
  2. Check everything but Offline
  3. OK

You should be good.

I don't know the equivalent mvn commands, if anyone could post them they could be useful.


You could try running the "mvn site" command and see what transitive dependencies you have, and then resolve potential conflicts (by ommitting an implicit dependency somewhere). Just a guess (it's a bit difficult to know what the problem could be without seeing your pom info)...


Add <sourceDirectory>src</sourceDirectory> in your pom.xml with proper reference. Adding this solved my problem


Just now I also met the problem

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

package com.foo.entry.common.domain does not exist
package com.foo.entry.common.model does not exist
package com.foo.entry.common.service does not exist
package com.foo.entry.common.util does not exist

Took a long time got the reason, that is one of the dependency jar is spring boot fat jar, so the solution is move below code in its pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

It COULD be due to insufficient heap memory.

It sounds strange, but try it, it might just work:

export MAVEN_OPTS='-Xms384M -Xmx512M -XX:MaxPermSize=256M'

Source: https://groups.google.com/group/neo4j/msg/e208be9ee1c101d7)


It also matters the order of the dependencies. I've had the same issue. And basically I had to put first the scope test and then scope compile dependencies in the pom.xml. If I put first the scope compile and then the scope test it will fail.


go to the maven repository and open the jar [tip: you can use winzip] of the source module to verify the specific class present.

In my case it is not. Then I found below.

if you are using the plugin org.apache.felix/maven-bundle-plugin

Make sure source module has export-package defined

example: com.xxx.camel.dao


Try to use:

mvn clean package install

This command should install your artifacts in you local maven repo.

PS: I see that this is an old question, but it may be helpful for somebody in the future.


i have an error like this, but after

1/

 mvn eclipse:clean
    mvn eclipse:eclipse -Dwtpversion=2.0

2/ run eclipse, and open the project

3/

mvn package

it's work