Vaadin项目执行mvn compile时出现MojoException编译错误求助
Hey there, let's break down your problems step by step—first fixing that mvn compile Mojo error, then setting up automatic view class compilation so you don't have to manually copy JARs around.
First: Diagnosing the Mojo Error
Mojo errors during mvn compile almost always tie to misconfigured Vaadin Maven plugin settings or version mismatches. Here's what to check first:
- Verify plugin-version alignment: Make sure your
vaadin-maven-pluginversion exactly matches your Vaadin 8 core version. For example, if you're using Vaadin 8.14.3, the plugin should also be on 8.14.3—mismatched versions often cause compilation failures. - Enable debug logging: Run
mvn clean compile -Xto get full, detailed error logs. The-Xflag will show exactly which Mojo is failing and why (e.g., widgetset compilation issues, missing dependencies, or classpath conflicts). This is critical for pinpointing the root cause. - Check Spring Boot compatibility: Vaadin 8 only works with Spring Boot 2.x (since Spring Boot 3+ drops Java 8 support, which Vaadin 8 relies on). If you're using Spring Boot 3.x, roll back to a 2.x version like 2.7.15.
Automating View Class Compilation (No Manual JAR Copies!)
You don't need to manually compile view classes into JARs and move them to app>Webapp>WEB-INF>classes—the Vaadin Maven plugin handles this automatically when configured correctly. Here's how to set it up:
Key POM Configurations
Ensure your pom.xml includes these critical sections (adjust versions to match your project):
<dependencies> <!-- Vaadin 8 Spring Boot Starter --> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-spring-boot-starter</artifactId> <version>8.14.3</version> <!-- Match your Vaadin 8 version --> </dependency> <!-- Mark Tomcat starter as provided for external deployment --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <!-- Spring Boot Maven Plugin --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.7.15</version> <!-- Compatible with Vaadin 8 --> </plugin> <!-- Vaadin Maven Plugin: Automates view/widgetset compilation --> <plugin> <groupId>com.vaadin</groupId> <artifactId>vaadin-maven-plugin</artifactId> <version>8.14.3</version> <!-- Match Vaadin core version --> <executions> <execution> <goals> <goal>compile</goal> <!-- Automatically compiles view classes --> <goal>update-theme</goal> <goal>update-widgetset</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
How It Works
When you run mvn package to build your WAR:
- The Vaadin plugin's
compilegoal processes your view classes, compiles them, and places the output in the correct location within the WAR (no manual copying needed). - The Spring Boot plugin packages everything into a deployable WAR that's ready for Tomcat.
Next Steps to Fix Your Issue
- Double-check your POM against the example above—fix any version mismatches or missing plugin executions.
- Run
mvn clean vaadin:compile compileto manually trigger Vaadin's compilation first, then standard compilation. This can isolate whether the issue is with Vaadin's plugin or general Maven setup. - If you still get the Mojo error, share the relevant snippet from the
mvn compile -Xlogs—this will let us pinpoint exactly what's breaking.
内容的提问来源于stack exchange,提问作者James Palfrey

