运行OptaPlanner组件时Maven构建失败求助
Let's break down your two Maven build failures with OptaPlanner and walk through actionable fixes for each scenario:
The core issue here is a test failure triggered by the Maven Surefire plugin, specifically an ExceptionInInitializerError during test execution. Here's how to address this:
Immediate Fix: Skip Tests to Complete Build
If you just need to get the build working first, skip the test phase entirely with this command:
mvn clean install -DskipTests
Root Cause Investigation
To fix the test failure permanently, check the detailed test reports at:
F:\optaplanner\optaplanner-master\optaplanner-webexamples\target\surefire-reports
Look for the specific test class that threw the initialization error. Common causes include:
- JDK Version Mismatch: OptaPlanner versions from 2018 typically require JDK 8. Verify your
JAVA_HOMEpoints to a compatible JDK. - Missing Dependencies: A required library might not be downloaded correctly. Run
mvn dependency:treeto check for missing or conflicting dependencies. - Configuration Issues: Some test classes might rely on external config files (like properties or XML) that are missing or misconfigured.
This failure is caused by the Maven Enforcer Plugin enforcing a rule that all dependencies use versions defined in the parent POM's dependency management section. The error flags com.graphhopper:graphhopper:jar as using an unmanaged version.
Fix Options:
Option 1: Use the Managed Dependency Version
Edit the pom.xml of the vrpdatasetgenerator module. Locate the com.graphhopper dependency and remove its explicit <version> tag. This will force it to inherit the version defined in the parent POM's <dependencyManagement> section.
Option 2: Exclude the Dependency from Enforcer Rules
If you need to use a custom version of GraphHopper, modify the enforcer plugin configuration in the module's pom.xml to exclude this dependency:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.4.1</version> <executions> <execution> <id>no-managed-deps</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <rule implementation="org.commonjava.maven.enforcer.rule.EnforceManagedDepsRule"> <excludes> <exclude>com.graphhopper:graphhopper</exclude> </excludes> </rule> </rules> </configuration> </execution> </executions> </plugin>
Option 3: Temporary Skip Enforcer (Not Recommended for Production)
For a quick temporary build, skip the enforcer plugin entirely:
mvn clean install -Denforcer.skip=true
内容的提问来源于stack exchange,提问作者Lion Leopard

