I see a lot of questions on stackoverflow on this. But still I\'m not able to know what is the issue in my way of building projects.
I\'ve two spring boot projects:
In my case in Spring Boot application I had the following service and accompanying non-public classes in a single ServiceFoo.java
file:
@Service
public class ServiceFoo {
}
class Foo { }
class Bar { }
At some point Maven started to fail with cannot find symbol: class Service
.
Only after moving classes Foo and Bar into separate java files (Foo.java
and Bar.java
respectively) the error disappeared. Looks like either Maven (3.5.2 and 3.6.3) or Java (1.8.0_201) bug.
I got the same error "cannot find symbol" .
I got 2 maven modules front and back and the front module could not access to the back module despite the dependency.
The problem was on the pom.xml in the back module. I remove these lines :
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
and I just got these lines in the front pom module.
Everytime I do maven "clean compile package install" goals on we-web I get the maven error. All the symbols that this complains isn't found are all in we-data project.
1) I think you should read the introduction about Maven pom here and lifecycle in Maven.
mvn clean compile package install
is redundant for compile and package phases since the install phase includes these phases (. So, do this only :
mvn clean install
2) Your web module where you run the maven goal requires the com.we:data:0.0.1-SNAPSHOT
dependency with your actual code :
<dependency>
<groupId>com.we</groupId>
<artifactId>data</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
If you add or modify code and you don't install this module, the web module cannot see these changes.
So you should do mvn clean install
in the com.we:data
module before doing that in the web module.
Finally the simplest to avoid having non updated dependency is running mvn clean install
from a multi-module project which aggregates these modules.
I've been stuck on this problem too for a day and finally found the root cause and solution here what i've done:
if you have the following lines on your pom (for your case is the we-data's pom)
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
you should remove those lines and change into:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
after got a clue from M. Deinum i found that he's correct about the jar compiled won't be a normal jar if you using spring-boot-maven-plugin
, thanks for the clue anyway.
and also please check this question: Dependency not found in Spring Boot project
I've tried to use this:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
it works like a charm.
In pom.xml, Add depedency
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
and class where you are using @Inject Import javax.inject.Inject import javax.inject.Inject
;