Issue when deploying Vaadin 14 app on Heroku

Viewed 1015

I have a problem when deploying Vaadin 14 app (Spring Boot) on Heroku. This is Heroku logs:

2019-10-23T19:34:19.005415+00:00 app[web.1]: 2019-10-23 19:34:19.004 ERROR 4 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]
     : Exception sending context initialized event to listener instance of class [com.vaadin.flow.spring.VaadinServletContextInitialize
r$DevModeServletContextListener]
2019-10-23T19:34:19.005427+00:00 app[web.1]:
2019-10-23T19:34:19.005432+00:00 app[web.1]: java.lang.IllegalStateException: Running project in development mode with no access to fol
der '/tmp/build_1eb1799fb4903b1c64716231dcb4a093'.
2019-10-23T19:34:19.005435+00:00 app[web.1]: Build project in production mode instead, see https://vaadin.com/docs/v14/flow/production/
tutorial-production-mode-basic.html
2019-10-23T19:34:19.005436+00:00 app[web.1]: at com.vaadin.flow.server.DeploymentConfigurationFactory.verifyFolderExists(DeploymentConf
igurationFactory.java:283) ~[flow-server-2.0.14.jar!/:2.0.14]
2019-10-23T19:34:19.005438+00:00 app[web.1]: at com.vaadin.flow.server.DeploymentConfigurationFactory.readBuildInfo(DeploymentConfigura
tionFactory.java:222) ~[flow-server-2.0.14.jar!/:2.0.14]
2019-10-23T19:34:19.005439+00:00 app[web.1]: at com.vaadin.flow.server.DeploymentConfigurationFactory.createInitParameters(DeploymentCo
nfigurationFactory.java:166) ~[flow-server-2.0.14.jar!/:2.0.14]
2019-10-23T19:34:19.005441+00:00 app[web.1]: at com.vaadin.flow.server.DeploymentConfigurationFactory.createPropertyDeploymentConfigura
tion(DeploymentConfigurationFactory.java:126) ~[flow-server-2.0.14.jar!/:2.0.14]
2019-10-23T19:34:19.005445+00:00 app[web.1]: at com.vaadin.flow.spring.VaadinServletContextInitializer$SpringStubServletConfig.createDe
ploymentConfiguration(VaadinServletContextInitializer.java:747) ~[vaadin-spring-12.0.6.jar!/:na]
2019-10-23T19:34:19.005447+00:00 app[web.1]: at com.vaadin.flow.spring.VaadinServletContextInitializer$DevModeServletContextListener.co
ntextInitialized(VaadinServletContextInitializer.java:289) ~[vaadin-spring-12.0.6.jar!/:na]
2019-10-23T19:34:19.005449+00:00 app[web.1]: at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4680) [tomc
at-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.00545+00:00 app[web.1]: at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5143) [tomca
t-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005451+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core
-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005452+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) [tomcat
-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005454+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) [tomcat
-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005456+00:00 app[web.1]: at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_222-heroku]
2019-10-23T19:34:19.005457+00:00 app[web.1]: at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java
:75) [tomcat-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005458+00:00 app[web.1]: at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) [
na:1.8.0_222-heroku]
2019-10-23T19:34:19.00546+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) [tomcat-emb
ed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005461+00:00 app[web.1]: at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841) [tomcat-embe
d-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005462+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core
-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005464+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) [tomcat
-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005465+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) [tomcat
-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005466+00:00 app[web.1]: at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_222-heroku]
2019-10-23T19:34:19.005467+00:00 app[web.1]: at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java
:75) [tomcat-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005469+00:00 app[web.1]: at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) [
na:1.8.0_222-heroku]
2019-10-23T19:34:19.00547+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) [tomcat-emb
ed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005472+00:00 app[web.1]: at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) [tomcat-
embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005473+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core
-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005474+00:00 app[web.1]: at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421) [tomca
t-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005475+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core
-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005485+00:00 app[web.1]: at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932) [tomcat-
embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005487+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core
-9.0.22.jar!/:9.0.22]

Due to logs the problem is in production mode. But I've set Heroku SPRING_PROFILES_ACTIVE environment variable to production.

heroku config:set SPRING_PROFILES_ACTIVE=production

Here is the pom.xml (build and profiles part):

<build>
    <defaultGoal>spring-boot:run</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <!-- Clean build and startup time for Vaadin apps sometimes may exceed
                 the default Spring Boot's 30sec timeout.  -->
            <configuration>
                <wait>500</wait>
                <maxAttempts>240</maxAttempts>
            </configuration>
        </plugin>

        <!--
            Take care of synchronizing java dependencies and imports in
            package.json and main.js files.
            It also creates webpack.config.js if not exists yet.
        -->
        <plugin>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-maven-plugin</artifactId>
            <version>${vaadin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-frontend</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <!-- Use the latest released version:
            https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
            <version>1.8.0</version>

            <executions>
                <execution>
                    <!-- optional: you don't really need execution ids, but it looks nice in your build log. -->
                    <id>install node and npm</id>
                    <goals>
                        <goal>install-node-and-npm</goal>
                    </goals>
                    <!-- optional: default phase is "generate-resources" -->
                    <phase>generate-resources</phase>
                </execution>
            </executions>
            <configuration>
                <nodeVersion>v10.16.2</nodeVersion>

                <!-- optional: with node version greater than 4.0.0 will use npm provided by node distribution -->
                <!--                    <npmVersion>2.15.9</npmVersion>-->

                <!-- optional: where to download node and npm from. Defaults to https://nodejs.org/dist/ -->
                <!--                    <downloadRoot>http://myproxy.example.org/nodejs/</downloadRoot>-->
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>production</id>
        <properties>
            <vaadin.productionMode>true</vaadin.productionMode>
        </properties>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>flow-server-production-mode</artifactId>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <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>
            </plugins>
        </build>
    </profile>
</profiles>

What am I doing wrong? I had no such problems deploying Vaadin 13 app on Heroku.

EDIT PROBLEM SOLVED Problem solved by running command

mvn clean package -Pproduction heroku:deploy
1 Answers

The problem was solved by implementing the following steps:

in build tag of pom.xml file add frontend-maven-plugin

<plugins>
    <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
          <!-- Use the latest released version:

          https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
        <version>LATEST_VERSION</version>
        ...
    </plugin>
…

Configure this plugin by adding execution goals and node version

<executions>
   <execution>
       <id>install node and npm</id>
       <goals>
           <goal>install-node-and-npm</goal>
       </goals>
       <phase>generate-resources</phase>
   </execution>
</executions>
<configuration>
     <nodeVersion>v10.16.2</nodeVersion>
</configuration>

In production profile for vaadin-maven-plugin add execution goal prepare-frontend

<profiles>
   <profile>
       <id>production</id>
       <properties>
           <vaadin.productionMode>true</vaadin.productionMode>
       </properties>
       <dependencies>
           <dependency>
               <groupId>com.vaadin</groupId>
               <artifactId>flow-server-production-mode</artifactId>
           </dependency>
       </dependencies>
       <build>
           <plugins>
               <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>
…

And finally, add heroku-maven-plugin with following configuration

<plugin>
   <groupId>com.heroku.sdk</groupId>
   <artifactId>heroku-maven-plugin</artifactId>
   <version>2.0.13</version>
   <configuration>
       <appName>vaadin-heroku-app</appName>
       <processTypes>
        <web>java $JAVA_OPTS -jar target/<project_name>.jar --server.port=$PORT</web>
       </processTypes>
   </configuration>
</plugin>

Heroku-maven-plugin provides direct deployment of prepackaged standalone web applications to Heroku.

Tag appName is the name of your Heroku app and is necessary only if your application is not under version control with Git.

Tag processTypes tells Heroku to start a web process and run .jar file.

To deploy Vaadin app in production mode to Heroku enter following command from the project directory

mvn clean package -Pproduction heroku:deploy

More details are here: how to deploy vaadin-14 app to heroku

Related