Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrate frontend-maven-plugin from maven to gradle

Tags:

java

gradle

I have a com.github.eirslett:frontend-maven-plugin in my maven project.

<plugin>
    <groupId>com.github.eirslett</groupId>
    <artifactId>frontend-maven-plugin</artifactId>
    <version>0.0.27</version>

    <executions>

        <execution>
            <id>install node and npm</id>
            <goals>
                <goal>install-node-and-npm</goal>
            </goals>
            <phase>generate-resources</phase>
        </execution>

        <execution>
            <id>npm install</id>
            <goals>
                <goal>npm</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
                <arguments>install</arguments>
            </configuration>
        </execution>

        <execution>
            <id>bower install</id>
            <goals>
                <goal>bower</goal>
            </goals>
            <phase>generate-resources</phase>

            <configuration>
                <arguments>install</arguments>
                <workingDirectory>${basedir}/src/main/webapp</workingDirectory>
            </configuration>
        </execution>

    </executions>

    <configuration>
        <nodeVersion>v4.2.4</nodeVersion>
        <npmVersion>2.7.1</npmVersion>
        <nodeDownloadRoot>https://nodejs.org/dist/</nodeDownloadRoot>
        <npmDownloadRoot>https://registry.npmjs.org/npm/-/</npmDownloadRoot>
        <workingDirectory>${basedir}/src/main/webapp</workingDirectory>

    </configuration>
</plugin>

Now I need to migrate it into gradle but I can't find examples how to do it. Grade migration tool translates only dependencies but not plugins. Is there some examples, how can I use frontend-maven-plugin in gradle?

like image 920
Kirill Avatar asked Aug 03 '16 08:08

Kirill


People also ask

How do I migrate from Maven to Gradle?

To convert Maven to Gradle, the only step is to run gradle init in the directory containing the POM. This will convert the Maven build to a Gradle build, generating a settings. gradle file and one or more build.

Can I use Maven plugins in Gradle?

You can't use a Maven plugin as-is in Gradle; you'll have to port it to a Gradle plugin. How difficult this is depends on how many Maven APIs the plugin is using. Another strategy might be to call into Maven via Gradle's Exec task.

Can you mix Maven and Gradle?

Short answer: yes. There's no conflict between having two independent build scripts for the same project, one in Maven and one in Gradle.


1 Answers

You may not find any example on how to use the frontend-maven-plugin in Gradle, as it is dedicated to Maven. But you may take a look at the Siouan Frontend Gradle plugin, which is an equivalent solution for Gradle, and allows to (from official website):

Integrate your frontend NPM/Yarn build into Gradle.

The usage and configuration seems close to your Maven configuration. Define the Node/NPM/Yarn version in your build.gradle file, link the scripts you want to be run depending on the Gradle lifecycle task (clean/assemble/check), and that's all. Below is a typical usage under Gradle 5.4 with NPM, taken from the docs:

// build.gradle
plugins {
    id 'org.siouan.frontend' version '1.1.0'
}

frontend {
    nodeVersion = '10.15.3'
    // See 'scripts' section in your 'package.json file'
    cleanScript = 'run clean'
    assembleScript = 'run assemble'
    checkScript = 'run check'
}

You'll notice:

  • Contrary to the frontend-maven-plugin, there's no declaration/configuration to trigger the frontend build with Gradle, as it is already provided out of the box. The download, installation of Node/NPM/Yarn requires no declaration/configuration - except the version numbers, as well as the build tasks. Just provide the NPM/Yarn command line to clean/assemble/check your frontend.
  • The mimimum supported version of Node shall be 6.2.1. So your initial configuration with 4.2.4 will require to migrate Node.
  • The plugin does not support Bower, and I don't think it will be supported in the future, as Bower now encourages migration to Yarn. You'll find a migration guide on Bower's website.
  • The plugin does not support the use of a specific NPM release. NPM being now packaged with Node, the plugin uses the version embedded in the downloaded Node distribution.

Regards

like image 122
Vincent Avatar answered Sep 19 '22 14:09

Vincent