4

For some reason this command works fine with my local machine:

mvn clean install -DskipTests=true -Psdk

However for Codeship it does now work and throws this "Cannot find symbol" error. In Codeship the full command is:

jdk_switcher use oraclejdk8
echo $JAVA_HOME
mvn clean install -DskipTests=true -Psdk

In the POM the repository have this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>

Error:

[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ client-app ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 65 source files to /home/rof/src/bitbucket.org/company/client-app/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/rof/src/bitbucket.org/company/client-app/src/main/java/com/client/rest/resources/MyResource.java:[3,61] cannot find symbol
symbol:   class MyEntity
Fabien
  • 859
  • 6
  • 15
quarks
  • 33,478
  • 73
  • 290
  • 513
  • 1
    We need to see the full error message. – JonK Apr 30 '15 at 14:42
  • 1
    You are missing a dependency or your code is the problem! – khmarbaise Apr 30 '15 at 14:46
  • I think it is pretty clear: `MyEntity` class is not included in the compilation classpath. – m0skit0 Apr 30 '15 at 14:55
  • There is two possible things: you don't have an import for `MyEntity` class in `MyResource` file or you don't have MyEntity class in your classpath. – Dawid Pura Apr 30 '15 at 15:01
  • Besides the answers provide by Dawid and m0skit0, you can try compiling using the same JDK on your local system. I realize that you POM specifically states 1.7, but its worth a shot to at least rule it out. I know i have seen similar issues like this in the past. – Jose Martinez Apr 30 '15 at 15:11
  • It is likely that you have the dependency for MyEntity.class on your class path on your local machine but not your remote build server (Codeship) it is missing, Can you post up your $PATH for both the codeship and local build machines? – Andrew McKee May 02 '15 at 11:33
  • I'm having a very similar issue, did you find the fix ? – coding_idiot Jan 04 '16 at 15:25
  • @coding_idiot not yet – quarks Jan 04 '16 at 19:00

4 Answers4

6

Your Maven is reading Java version as 1.8, Where as the pom.xml says the version is 1.7.

Try installing the required verison.

If already installed check your $JAVA_HOME environment variable, it should contain the path of Java JDK 8. If you dont find it, fix your environment variable.

also remove the lines

 <fork>true</fork>
     <executable>${JAVA_1_8_HOME}/bin/javac</executable>

from the pom.xml

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
3

I had the same issue. reason was one of the class was used in

src/main/java/

Where as in actual it was present in

src/test/java
user4906240
  • 605
  • 1
  • 6
  • 20
3

If you have correctly imported dependency the you can try the following process.
First try-
mvn clean
if that runs successfully then try-
mvn install
If this works fine then you can try-
mvn compile
This process worked for me.

Pritom
  • 49
  • 1
  • Btw, this issue can occur because of multiple reasons. First, dependency issue. Second, reference issue. etc. If all the issue has been resolved and you still get the error then you can try the above process. – Pritom Sep 01 '17 at 03:40
0

I had the similar issue but when I changed Testng version in POM it resolved the issue.

<artifactId>testng</artifactId>
<version>6.9.8</version>       // Changed the version to 6.9.8
<scope>test</scope>