vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
623 stars 167 forks source link

Make it possible to check production mode in code without a servlet reference #8824

Open Artur- opened 4 years ago

Artur- commented 4 years ago

The way to enable production mode in a starter project is to use

mvn -Pproduction

This in turn does

            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>flow-server-production-mode</artifactId>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                            <jvmArguments>-Dvaadin.productionMode</jvmArguments>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <version>${vaadin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build-frontend</goal>
                                </goals>
                                <phase>compile</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>

There is nothing here that is specific to any servlet. The system property is global, the dependency is global.

Yet, if you want to check in code if you are in production mode or not, you need a reference to a DeploymentConfiguration that is owned by a VaadinService which is tied to a VaadinServlet.

There does not seem to be any benefit of this arrangement and the downside that you cannot check the development/production mode without a servlet/service reference.

What I would like to do is e.g.

    @EventListener({ ApplicationReadyEvent.class })
    private void applicationReadyEvent() {
      if (Vaadin.isProductionMode()) {
        return;
      }
      openBrowser("http://localhost:8080");
    }
Legioth commented 4 years ago

The production profile is the default way of enabling and disabling production mode, but it's not the only way of doing it. The other way is based on a servlet init parameter, which is indeed tied to a specific instance. We could consider removing that way of controlling the development mode, but doing that would also require a consideration for backwards compatibility.