eirslett / frontend-maven-plugin

"Maven-node-grunt-gulp-npm-node-plugin to end all maven-node-grunt-gulp-npm-plugins." A Maven plugin that downloads/installs Node and NPM locally, runs NPM install, Grunt, Gulp and/or Karma.
Apache License 2.0
4.26k stars 871 forks source link

[Question]? Configuration is not read #1158

Closed eyp closed 2 months ago

eyp commented 3 months ago

I'm trying just to run the install-node-and-npm goal. Following the example project, if I configure the plugin like this:

                    <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.15.0</version>

                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <!-- mvn frontend:install-node-and-npm -->
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <configuration>
                            <nodeVersion>v17.9.1</nodeVersion>
                        </configuration>
                    </execution>
                </executions>

            </plugin>

I get this error:

The parameters 'nodeVersion' for goal com.github.eirslett:frontend-maven-plugin:1.15.0:install-node-and-npm are missing or invalid

To avoid the issue and install the specified NodeJs version I need to move the configuration section outside the execution:

                      <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>${frontend.maven.plugin.version}</version>

                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <!-- mvn frontend:install-node-and-npm -->
                            <goal>install-node-and-npm</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- See https://nodejs.org/en/download/ for latest node and npm (lts) versions -->
                    <nodeVersion>v17.9.1</nodeVersion>
                </configuration>
            </plugin>

Also, I have a related problem with the other kind of goals like npm. It always does the default install command instead of reading the configuration I specified:

 mvn frontend:npm
<execution>
  <id>npm run eslint</id>
  <goals>
    <goal>npm</goal>
  </goals>
  <configuration>
    <arguments>run eslint</arguments>
  </configuration>
</execution>
[INFO] Running 'npm install' in ...
neoxpert commented 3 months ago

I don't think this is purely and issue of the frontend plugin, but the way of how Maven works. A Maven build always consists of several phases (clean, compile, test-compile, test ..). Plugins may hook into those phases with several goals, like the compiler plugin attaching its compile goal to the compile phase and the testCompile goal to the test-compile phase.

Regarding the frontend plugin install-node-and-npm and npm are goals, that are bound to the generate-resources phase be default. So if you would call mvn generate-resources those goals would be executed. Adding an execution configuration could be used to bind these goals to another phase. Or offer additional configuration / execution steps for a certain goal.

By using or adding an execution step, you may rebind a goal to another phase. So instead of running the goal install-node-and-npm you could make it to be executed within the clean phase of maven. What the execution configuration do not do is overriding the configurations of a goal when calling it directly.

Calling mvn frontend:install-node-and-npm will indeed invoke this exact goal offered by the plugin. But Maven will not lookup the configuration within the exeuction elements but the default plugin configuration. So having a basic configuration like this would work:

<plugin>
  <groupId>com.github.eirslett</groupId>
  <artifactId>frontend-maven-plugin</artifactId>
  <version>1.15.0</version>
  <configuration>
    <nodeVersion>v17.9.1</nodeVersion>
  </configuration>
</plugin>

Changing the configuration of the plugin to this one:

<plugin>
  <groupId>com.github.eirslett</groupId>
  <artifactId>frontend-maven-plugin</artifactId>
  <version>1.15.0</version>
  <executions>
    <execution>
      <id>install node and npm</id>
      <goals>
        <goal>install-node-and-npm</goal>
      </goals>
      <configuration>
        <nodeVersion>v17.9.1</nodeVersion>
      </configuration>
    </execution>
  </executions>
</plugin>

will cause mvn frontend:install-node-and-npm to fail as the required nodeVersion is not configured for the direct invocation of the goal. If you would call it like mvn frontend:install-node-and-npm -DnodeVersion=v17.9.1 it would work again. Also calling mvn generate-resources would work, as the execution step would tell Maven "hey, if we are at the install-node-and-npm goal, consider this configuration". But what also would work, would be calling the install-node-and-npm with an explicit identifier (that's what the is for). mvn frontend:install-node-and-npm@"install node and npm" (quoted due to the whitespaces in the id) would call the goal with the configuration stated in the given execution element.

eyp commented 2 months ago

Yes, I didn't mean it was an issue of the plugin (that's why I tagged it as a question). Thanks for the reply, it's useful.