vaadin / vaadin-gradle-plugin

Gradle plugin for Vaadin 14 applications. Takes care of front-end build, helps to configure repositories and to create various project and file templates.
Apache License 2.0
31 stars 9 forks source link

Error with multi-project build #112

Closed tarekoraby closed 3 years ago

tarekoraby commented 3 years ago

Desktop (please complete the following information):

Describe the bug Attempting a multi-project build, produces an error

To Reproduce Unzip the attached base-starter-gradle-submodule-test.zip and run vaadinPrepareFrontend

Expected behavior The project runs

Actual behavior The following error is produced

Execution failed for task ':apps:user-administration:vaadinPrepareFrontend'. Caused by: java.lang.NoSuchMethodError: 'void org.apache.commons.io.FileUtils.forceMkdirParent(java.io.File)'
at com.vaadin.flow.server.frontend.NodeUpdater.writePackageFile(NodeUpdater.java:374)
at com.vaadin.flow.server.frontend.NodeUpdater.writePackageFile(NodeUpdater.java:368)
at com.vaadin.flow.server.frontend.TaskCreatePackageJson.execute(TaskCreatePackageJson.java:49)
at com.vaadin.flow.server.frontend.NodeTasks.execute(NodeTasks.java:514)
mvysny commented 3 years ago

Thank you! The problem seems to be that the FileUtils.forceMkdirParent() method is missing, which suggests that something pulls in older commons-io onto the Vaadin plugin's classpath.

If you run ./gradlew buildEnvironment then you can see that the Gretty plugin 3.0.4 is indeed pulling in commons-io:2.4, while Vaadin Gradle plugin requires commons-io:2.5.

In order to fix this, make sure to apply the Vaadin Gradle plugin in the root project as follows:

root build.gradle:

plugins {
    id 'org.gretty' version '3.0.4'
    id 'com.vaadin' version '0.14.5.1' apply false
}

repositories {
    mavenCentral()
}

subproject's build.gradle:

plugins {
    id 'war'
    id 'com.vaadin'
}

Now you can verify via ./gradlew buildEnvironment that the Vaadin Gradle plugin causes Gradle to use commons-io:2.5 also for Gretty plugin (which is okay since commons-io is backward compatible):

/gradlew buildEnvironment|grep commons-io
|         |    +--- commons-io:commons-io:2.4 -> 2.5
          |    |    +--- commons-io:commons-io:2.5

Therefore, it's not really a bug in the plugin, but rather in how Gradle constructs plugin classpath for subprojects.

The solution is therefore to declare the com.vaadin plugin in the root project and only apply it in appropriate subprojects.

Since it's not a bug in the plugin, closing as won't fix.