Skip to content

Commit

Permalink
Add vaadin-dev exclusion to Maven profile
Browse files Browse the repository at this point in the history
Closes gh-1492
  • Loading branch information
mhalbritter committed Jun 3, 2024
1 parent 5c46018 commit e6e69bb
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,29 @@

package io.spring.start.site.extension.dependency.vaadin;

import io.spring.initializr.generator.buildsystem.Dependency;
import io.spring.initializr.generator.buildsystem.maven.MavenBuild;
import io.spring.initializr.generator.buildsystem.maven.MavenProfile;
import io.spring.initializr.generator.spring.build.BuildCustomizer;

/**
* A {@link BuildCustomizer} that adds a production profile to enable Vaadin's production
* mode.
*
* @author Stephane Nicoll
* @author Moritz Halbritter
*/
class VaadinMavenBuildCustomizer implements BuildCustomizer<MavenBuild> {

@Override
public void customize(MavenBuild build) {
build.profiles()
.id("production")
.plugins()
MavenProfile profile = build.profiles().id("production");
profile.dependencies()
.add("vaadin-core",
Dependency.withCoordinates("com.vaadin", "vaadin-core")
.exclusions(new Dependency.Exclusion("com.vaadin", "vaadin-dev"))
.build());
profile.plugins()
.add("com.vaadin", "vaadin-maven-plugin", (plugin) -> plugin.version("${vaadin.version}")
.execution("frontend",
(execution) -> execution.goal("prepare-frontend").goal("build-frontend").phase("compile")));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.start.site.extension.dependency.vaadin;

import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link VaadinMavenBuildCustomizer}.
*
* @author Moritz Halbritter
*/
class VaadinMavenBuildCustomizerTests extends AbstractExtensionTests {

@Test
void shouldAddProductionProfile() {
ProjectRequest projectRequest = createProjectRequest("vaadin", "web");
assertThat(mavenPom(projectRequest)).hasProfile("production").lines().containsSequence(
// @formatter:off
" <profile>",
" <id>production</id>",
" <dependencies>",
" <dependency>",
" <groupId>com.vaadin</groupId>",
" <artifactId>vaadin-core</artifactId>",
" <exclusions>",
" <exclusion>",
" <groupId>com.vaadin</groupId>",
" <artifactId>vaadin-dev</artifactId>",
" </exclusion>",
" </exclusions>",
" </dependency>",
"",
" </dependencies>",
" <build>",
" <plugins>",
" <plugin>",
" <groupId>com.vaadin</groupId>",
" <artifactId>vaadin-maven-plugin</artifactId>",
" <version>${vaadin.version}</version>",
" <executions>",
" <execution>",
" <id>frontend</id>",
" <phase>compile</phase>",
" <goals>",
" <goal>prepare-frontend</goal>",
" <goal>build-frontend</goal>",
" </goals>",
" </execution>",
" </executions>",
" </plugin>",
" </plugins>",
" </build>",
" </profile>"
);
// @formatter:on
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,50 @@
*/
class VaadinProjectGenerationConfigurationTests extends AbstractExtensionTests {

private static final String SPRING_BOOT_VERSION = "3.2.0";
private static final String SPRING_BOOT_VERSION = "3.3.0";

@Test
void mavenBuildWithVaadinAddProductionProfileWithoutProductionModeFlag() {
ProjectRequest request = createProjectRequest("vaadin", "data-jpa");
request.setBootVersion(SPRING_BOOT_VERSION);
assertThat(mavenPom(request)).hasProfile("production")
.lines()
.containsSequence(" <profile>", " <id>production</id>", " <build>",
" <plugins>", " <plugin>",
" <groupId>com.vaadin</groupId>",
" <artifactId>vaadin-maven-plugin</artifactId>",
" <version>${vaadin.version}</version>",
" <executions>", " <execution>",
" <id>frontend</id>",
" <phase>compile</phase>", " <goals>",
" <goal>prepare-frontend</goal>",
" <goal>build-frontend</goal>",
" </goals>", " </execution>",
" </executions>", " </plugin>", " </plugins>",
" </build>", " </profile>");
assertThat(mavenPom(request)).hasProfile("production").lines().containsSequence(
// @formatter:off
" <profile>",
" <id>production</id>",
" <dependencies>",
" <dependency>",
" <groupId>com.vaadin</groupId>",
" <artifactId>vaadin-core</artifactId>",
" <exclusions>",
" <exclusion>",
" <groupId>com.vaadin</groupId>",
" <artifactId>vaadin-dev</artifactId>",
" </exclusion>",
" </exclusions>",
" </dependency>",
"",
" </dependencies>",
" <build>",
" <plugins>",
" <plugin>",
" <groupId>com.vaadin</groupId>",
" <artifactId>vaadin-maven-plugin</artifactId>",
" <version>${vaadin.version}</version>",
" <executions>",
" <execution>",
" <id>frontend</id>",
" <phase>compile</phase>",
" <goals>",
" <goal>prepare-frontend</goal>",
" <goal>build-frontend</goal>",
" </goals>",
" </execution>",
" </executions>",
" </plugin>",
" </plugins>",
" </build>",
" </profile>"
);
}

@Test
Expand Down

0 comments on commit e6e69bb

Please sign in to comment.