question
There is a springboot project B as a dependency of another project A. Its startup class needs to be excluded when B is packaged.
According to Baidu, you only need to add the following configuration to exclude it.
<build> <!--Package project package name--> <finalName>${}</finalName> <plugins> <plugin> <groupId></groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <excludes> <exclude>**/</exclude> </excludes> </configuration> </plugin> </plugins> </build>
However, after actual packaging, it was found that the exclusion did not take effect.
reason
1. The excluded class is imported in a certain class C. If class C wants to compile, it must compile the excluded class, so C must be excluded at the same time.
pom introduced this class, causing exclude to not take effect
Solution
Unit tests were written in Project B and annotations were used
@SpringBootTest(classes={})
So when compiling test, the startup class was forced to be compiled.
So onlySkip compilation testOr comment out
@SpringBootTest(classes={})
<properties> <!--Skip the compilationtest--> <>true</> <!--Skip to execute unit tests--> <skipTests>true</skipTests> </properties>
<build> <!--Package project package name--> <finalName>${}</finalName> <plugins> <plugin> <groupId></groupId> <artifactId>maven-compiler-plugin</artifactId> <!--coverparent pomConfiguration--> <configuration ="override"> <excludes> <exclude>**/</exclude> </excludes> </configuration> </plugin> </plugins> </build>
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.