Skip to content

Commit b2c4b9a

Browse files
jorgheymansclaudemcollovati
authored
feat: allow skipping Vaadin maven plugin execution during a build (#22516)
* Add vaadin.skip parameter to bypass plugin execution - Added skip parameter to FlowModeAbstractMojo with property "vaadin.skip" - Added early return in execute() method when skip=true - Added informative log message when skipping - Created integration test and unit test for skip functionality - Parameter can be used with: mvn clean install -Dvaadin.skip 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * revert Clippy Claude things * Fix test * fix maven version * fix test compilation error * use invoker to verify the build was skipped * configure skip directly on the plugin instead of profile * typo * better invoker command as suggested * format --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Marco Collovati <marco@vaadin.com>
1 parent 84b2362 commit b2c4b9a

File tree

6 files changed

+192
-0
lines changed

6 files changed

+192
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright 2000-2025 Vaadin Ltd.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
# use this file except in compliance with the License. You may obtain a copy of
6+
# the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations under
14+
# the License.
15+
#
16+
17+
invoker.goals=clean flow:prepare-frontend
18+
invoker.buildResult=success
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.vaadin.test.maven</groupId>
7+
<artifactId>vaadin-skip-test</artifactId>
8+
<version>1.0</version>
9+
<packaging>jar</packaging>
10+
11+
<description>
12+
Tests the vaadin.skip parameter functionality.
13+
</description>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<maven.compiler.release>21</maven.compiler.release>
18+
<maven.compiler.source>${maven.compiler.release}</maven.compiler.source>
19+
<maven.compiler.target>${maven.compiler.release}</maven.compiler.target>
20+
<maven.test.skip>true</maven.test.skip>
21+
<flow.version>@project.version@</flow.version>
22+
</properties>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>com.vaadin</groupId>
27+
<artifactId>flow-server</artifactId>
28+
<version>${flow.version}</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>com.vaadin</groupId>
32+
<artifactId>flow-client</artifactId>
33+
<version>${flow.version}</version>
34+
</dependency>
35+
</dependencies>
36+
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<groupId>org.apache.maven.plugins</groupId>
41+
<artifactId>maven-compiler-plugin</artifactId>
42+
<version>3.13.0</version>
43+
</plugin>
44+
<plugin>
45+
<groupId>com.vaadin</groupId>
46+
<artifactId>flow-maven-plugin</artifactId>
47+
<version>${flow.version}</version>
48+
<configuration>
49+
<skip>true</skip>
50+
</configuration>
51+
</plugin>
52+
</plugins>
53+
</build>
54+
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.vaadin.test;
2+
3+
import com.vaadin.flow.component.Component;
4+
import com.vaadin.flow.router.Route;
5+
6+
@Route
7+
public class SkipTestView extends Component {
8+
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import java.nio.file.*;
2+
3+
flowTsx = basedir.toPath().resolve("build.log");
4+
if ( !Files.exists(flowTsx, new LinkOption[0]) )
5+
{
6+
throw new RuntimeException("build.log not found");
7+
}
8+
9+
lines = Files.readString(flowTsx);
10+
if ( !lines.contains("Skipping Vaadin build") )
11+
{
12+
throw new RuntimeException("Vaadin build not skipped");
13+
}

flow-plugins/flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/FlowModeAbstractMojo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ public abstract class FlowModeAbstractMojo extends AbstractMojo
313313
+ InitParameters.COMMERCIAL_WITH_BANNER, defaultValue = "false")
314314
private boolean commercialWithBanner;
315315

316+
/**
317+
* Skip the execution of this plugin.
318+
*/
319+
@Parameter(property = "vaadin.skip", defaultValue = "false")
320+
private boolean skip;
321+
316322
static final String CLASSFINDER_FIELD_NAME = "classFinder";
317323
private ClassFinder classFinder;
318324

@@ -325,6 +331,11 @@ void setBuildContext(BuildContext buildContext) {
325331

326332
@Override
327333
public void execute() throws MojoExecutionException, MojoFailureException {
334+
if (skip) {
335+
getLog().info("Skipping Vaadin build");
336+
return;
337+
}
338+
328339
PluginDescriptor pluginDescriptor = mojoExecution.getMojoDescriptor()
329340
.getPluginDescriptor();
330341
checkFlowCompatibility(pluginDescriptor);
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2000-2025 Vaadin Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package com.vaadin.flow.plugin.maven;
17+
18+
import java.io.File;
19+
20+
import org.apache.maven.plugin.logging.Log;
21+
import org.codehaus.plexus.util.ReflectionUtils;
22+
import org.junit.Before;
23+
import org.junit.Rule;
24+
import org.junit.Test;
25+
import org.junit.rules.TemporaryFolder;
26+
import org.mockito.Mockito;
27+
28+
import static com.vaadin.flow.plugin.maven.BuildFrontendMojoTest.setProject;
29+
import static org.mockito.Mockito.never;
30+
import static org.mockito.Mockito.verify;
31+
32+
public class SkipExecutionTest {
33+
34+
@Rule
35+
public TemporaryFolder temporaryFolder = new TemporaryFolder();
36+
37+
private PrepareFrontendMojo mojo;
38+
private Log mockLog;
39+
private File projectBase;
40+
41+
@Before
42+
public void setup() throws Exception {
43+
mojo = new PrepareFrontendMojo();
44+
mockLog = Mockito.mock(Log.class);
45+
projectBase = temporaryFolder.getRoot();
46+
47+
// Set up the mojo with basic configuration
48+
ReflectionUtils.setVariableValueInObject(mojo, "projectBasedir",
49+
projectBase);
50+
ReflectionUtils.setVariableValueInObject(mojo, "frontendDirectory",
51+
new File(projectBase, "src/main/frontend"));
52+
53+
setProject(mojo, projectBase);
54+
55+
// Use reflection to set the mock logger
56+
ReflectionUtils.setVariableValueInObject(mojo, "log", mockLog);
57+
}
58+
59+
@Test
60+
public void testSkipExecutionWhenVaadinSkipIsTrue() throws Exception {
61+
// Set the skip parameter to true
62+
ReflectionUtils.setVariableValueInObject(mojo, "skip", true);
63+
64+
// Execute the mojo
65+
mojo.execute();
66+
67+
// Verify that the skip message was logged
68+
verify(mockLog).info("Skipping Vaadin build");
69+
}
70+
71+
@Test
72+
public void testNormalExecutionWhenVaadinSkipIsFalse() throws Exception {
73+
// Set the skip parameter to false (default)
74+
ReflectionUtils.setVariableValueInObject(mojo, "skip", false);
75+
76+
try {
77+
// Execute the mojo - this might fail due to missing dependencies in
78+
// test env
79+
mojo.execute();
80+
} catch (Exception e) {
81+
// Expected - we're just testing that skip message is not logged
82+
}
83+
84+
// Verify that the skip message was NOT logged
85+
verify(mockLog, never()).info("Skipping Vaadin build");
86+
}
87+
}

0 commit comments

Comments
 (0)