Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for spring-boot:run into flow-maven-plugin #3514

Closed
vlukashov opened this issue Feb 8, 2018 · 5 comments
Closed

add support for spring-boot:run into flow-maven-plugin #3514

vlukashov opened this issue Feb 8, 2018 · 5 comments

Comments

@vlukashov
Copy link

As a developer I want to use the Spring Boot maven plugin to run my Flow app in the production mode (because running the spring-boot:run maven goal is easier then deploying a .war file to a servlet container, and because it's easier to debug the app started that way). Currently (with the version 1.0.0.alpha19 of the flow-maven-plugin) that requires extra configuration and manual action when re-building the app.

The flow-maven-plugin runs a Gulp build script and outputs production-ready frontend files into the folder defined in the transpileOutputDirectory configuration property (${project.build.directory}/${project.build.finalName}/ by default).

When the app is packaged in a .war file, this would be the context root. That matches the default context paths for the frontend resources expected by Flow (see FRONTEND_URL_ES5_DEFAULT_VALUE). However, when the app is started with spring-boot:run, the context root is src/main/webapp, and Flow would search for frontend resources there.

When the app started with jetty:run, this can be worked around by instructing the Maven Jetty plugin to add extra resource folders to the context:

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <configuration>
        <webAppConfig>
            <resourceBases>
                <resourceBase>${project.build.directory}/${project.build.finalName}</resourceBase>
            </resourceBases>
        </webAppConfig>
    </configuration>
</plugin>

But there is no similar parameters for the Spring-Boot Maven plugin.

A semi-OK workaround for this issue is to configure the Flow Maven plugin to output the transpiled frontend code into a subfolder in src/main/webapp (<transpileOutputDirectory>${frontend.directory}/build</transpileOutputDirectory>), and then also override the default Flow settings for the frontend resource folders with -Dvaadin.frontend.url.es5=context://frontend/build/frontend-es5/ and -Dvaadin.frontend.url.es6=context://frontend/build/frontend-es6/.

The problem with this workaround (apart from the fact that it adds generated code into the source folder) is that when running the flow-maven-plugin in the second time, the Gulp build script fails to clean the output folder (because it is outside of the Gulp's working directory):

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 44.049 s
[INFO] Finished at: 2018-02-08T11:32:33+02:00
[INFO] Final Memory: 48M/1469M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.vaadin:flow-maven-plugin:1.0.0.alpha19:package-for-production (default) on project bakery-app-starter-flow-spring: Execution default of goal com.vaadin:flow-maven-plugin:1.0.0.alpha19:package-for-production failed: Transpilation with gulp has failed: 'gulp build_es6' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]

That is, this workaround requires deleting the build output folder manually. Please improve the developer experience for this use case.

@tsuoanttila
Copy link
Contributor

Would <folders> work for this?

@vlukashov
Copy link
Author

vlukashov commented Feb 9, 2018

@tsuoanttila does not looks like that. The documentation says it adds more folders to the classpath, but apparently not to the servlet context. I've tried adding the ${project.build.directory}/${project.build.finalName} folder and that did not add the resources from that folder to the context.

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <folders>
            <folder>${project.build.directory}/${project.build.finalName}</folder>
        </folders>
    </configuration>
</plugin>

@vlukashov
Copy link
Author

I ended up using the default config for the flow maven plugin (outputs the transpiled frontend sources to ${project.build.directory}/${project.build.finalName}/frontend-es5 and ${project.build.directory}/${project.build.finalName}/frontend-es6), and copy the frontend-esX folders into src/main/webapp/ with the maven resources plugin.

With that approach both the .war context and the mvn spring-boot:run context have the frontend files where Flow expects to find them (/frontend-es5 and /frontend-es6). Restarting the app with mvn spring-boot:run also works. But that's a manual configuration that ideally should not be there.

@SomeoneToIgnore
Copy link
Contributor

Now the plugin is able to remove the external directories: #3540

@denis-anisimov
Copy link
Contributor

Issue moved to vaadin/spring #267 via ZenHub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants