mvysny / karibu-testing

Vaadin Server-Side Browserless Containerless Unit Testing
Apache License 2.0
111 stars 14 forks source link

Problem with the check: "polymer 3 webjar is on the classpath, indicating compatibility mode:" #56

Closed vlipovetskii closed 3 years ago

vlipovetskii commented 3 years ago

karibu-testing 1.2.7

I don't leverage compatibility mode (see more below), but still have polymer:jar in the dependencies and on classpath. npm is leveraged to populate node_modules and to build vaadin front-end stuff (.gz, .js)

...

                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <version>${vaadin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>prepare-frontend</goal>
                                    <goal>build-frontend</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

... application.properties ... vaadin.compatibilityMode=false ...

maven dependency tree fragment, demonstrating presence of org.webjars.bowergithub.polymer:polymer:jar:2.6.1:compile without compatibility mode. ...

[INFO] |  |  \- com.vaadin:vaadin-core:jar:14.4.5:compile
[INFO] |  |     +- com.vaadin:flow-html-components:jar:2.4.4:compile
[INFO] |  |     +- com.vaadin:flow-data:jar:2.4.4:compile
[INFO] |  |     +- com.vaadin:flow-dnd:jar:2.4.4:compile
[INFO] |  |     |  +- org.webjars.npm:vaadin__vaadin-mobile-drag-drop:jar:1.0.0:compile
[INFO] |  |     |  \- org.webjars.npm:mobile-drag-drop:jar:2.3.0-rc.1:compile
[INFO] |  |     +- com.vaadin:vaadin-lumo-theme:jar:2.4.4:compile
[INFO] |  |     |  +- org.webjars.bowergithub.vaadin:vaadin-lumo-styles:jar:1.6.0:compile
[INFO] |  |     |  +- org.webjars.bowergithub.polymerelements:iron-icon:jar:2.1.0:compile
[INFO] |  |     |  +- org.webjars.bowergithub.polymerelements:iron-meta:jar:2.1.1:compile
[INFO] |  |     |  +- org.webjars.bowergithub.polymerelements:iron-iconset-svg:jar:2.2.1:compile
[INFO] |  |     |  +- org.webjars.bowergithub.polymerelements:iron-flex-layout:jar:2.0.3:compile
[INFO] |  |     |  +- org.webjars.bowergithub.polymer:polymer:jar:2.6.1:compile
...
mvysny commented 3 years ago

Hello! Since you're using (p)npm mode, those webjars are not being used in your app at all, and only increase the size of your application. The best way is to exclude them from the vaadin-core dependency as follows:

        <dependency>
            <groupId>com.vaadin</groupId>
            <!-- Replace artifactId with vaadin-core to use only free components -->
            <artifactId>vaadin-core</artifactId>
            <exclusions>
                <!-- Webjars are only needed when running in Vaadin 13 compatibility mode -->
                <exclusion>
                    <groupId>com.vaadin.webjar</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.insites</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.polymer</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.polymerelements</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.vaadin</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.webcomponents</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

Please see https://github.com/mvysny/karibu10-helloworld-application-maven/blob/master/pom.xml for more details.

vlipovetskii commented 3 years ago

Thank you ! It works now.

mvysny commented 3 years ago

Perfect, good to know! Closing this issue, please feel free to reopen if you think Karibu should detect the pnpm mode in a different way.

mvysny commented 2 years ago

I'm adding more information to the ticket, in hopes that it may be useful to someone in the future.

Karibu-Testing doesn't support compatibility mode anymore (the webjar mode which Vaadin 13 and lower used to use). Karibu-Testing tests the presence of the compatibility mode by trying to figure out whether the polymer 2 webjar is on the classpath. The test is rather simple: we try to load the META-INF/resources/webjars/polymer/polymer.html resource from the classpath, failing if it exists. The file is present in the org.webjars.bowergithub.polymer:polymer:2.7.0 jar file.

If you're absolutely sure that you're not using compatibility mode but Karibu-Testing still fails, please make sure that the polymer-2.7.0.jar is not on your testRuntime classpath. This jar is pulled transitively by Vaadin 14, therefore you should be able to get rid of the file by excluding it from the vaadin-core dependency as shown above.

However, you might be using some Vaadin add-ons which transitively depend on vaadin-core and aren't excluding the webjars; the webjars are then pulled in as a transitive dependency for those Vaadin add-ons.

You can examine where the polymer.jar is coming from, by running either ./gradlew dependencies or mvn dependency:tree, then excluding the polymer.jar from all of those places. Alternatively, you could upgrade to Vaadin 22+ since newer Vaadins don't depend on webjars at all. You can also open your project in Eclipse or Intellij then browse the list of dependencies, to spot whether the polymer.jar dependency is there or not.