Search code examples
vaadinvaadin-flowvaadin14

Vaadin @CssImport not working in jar dependency


I can't seem to get the @CssImport annotation working when the component class is in a separate jar. (Main web project is Vaadin 18)

I checked out the addon starter:

https://github.com/vaadin/addon-starter-flow

And adjusted the TheAddon class to add a css class name:

@CssImport("./theaddon.css")
public class TheAddon extends Div {

    public TheAddon() {
        setText("Hello");
        addClassName("theaddon");
        
    }
}

I then added the theaddon.css file to:

src\main\resources\META-INF\resources\frontend\theaddon.css

With the styles:

.theaddon {
    color:Red;
}

However when I use the addon, I do not see the style applied. I do see the style if I extend the TheAddon class within my web project. So this leads me to believe there's some classpath magic that isn't happening correctly.


Solution

  • Argh - the issue was that the vaadin.whitelisted-packages property was set. Thus Vaadin was not scanning / finding the components when building the front-end. Correcting this property fixed it.