Packaging a Theme for Reuse
A custom theme can be packaged into a JAR file for use in multiple applications as follows:
-
Create a new Maven project with the following structure and add your theme files to the theme folder (1):
Source code
[project root] ├── src │ └── main │ └── resources │ └── META-INF │ └── resources │ └── themes │ └── my-theme (1) └── pom.xml -
Update
pom.xmlas follows:-
Add the Vaadin version property:
Source code
pom.xml<vaadin.version>14.13.2</vaadin.version> -
Add dependency management:
Source code
XML
<dependencyManagement> <dependencies> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-bom</artifactId> <version>${vaadin.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> -
Update dependencies to only contain the following:
Source code
XML
<dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin</artifactId> <scope>provided</scope> </dependency>
-
-
If the theme uses npm assets, as described in Style Sheets From npm Packages, add a
Dependencies.javaclass (1) with the corresponding@NpmPackageannotations:Source code
[project root] └── src └── main └── java └── com └── vaadin └── flow └── theme └── Dependencies.java (1)NoteDependency class packageThe package in which the java class is placed does not have to becom.vaadin.flow.themepackage as in the example above, but it is recommended for themes that are going to be used in Vaadin Spring Boot applications, as it is always automatically scanned. Other recommended packages arecom.vaadin.flow.componentandcom.vaadin.shrinkwrap. See Vaadin’s Spring package scanning documentation for using other custom packages. -
Create the JAR with
mvn install.
To use the packaged theme in an application, add the JAR as a dependency and apply the theme using the @Theme annotation.
2F0CE41F-B2B3-44B0-A9EF-4F1A11EBEADF