将frontend-maven-plugin从maven迁移到gradle

Kir*_*ill 11 java gradle

com.github.eirslett:frontend-maven-plugin我的maven项目中有一个.

<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>
Run Code Online (Sandbox Code Playgroud)

现在我需要将其迁移到gradle但我无法找到如何做到的示例.成绩迁移工具仅转换依赖项,但不转换插件.有一些例子,我怎样才能使用frontend-maven-plugingradle

Vin*_*ent 8

您可能找不到关于如何frontend-maven-plugin在 Gradle 中使用 的任何示例,因为它专用于 Maven。但是你可以看看Siouan Frontend Gradle plugin,它是 Gradle 的等效解决方案,并允许(来自官方网站):

将您的前端 NPM/Yarn 构建集成到 Gradle 中。

用法和配置似乎与您的 Maven 配置很接近。在你的build.gradle文件中定义 Node/NPM/Yarn 版本,根据 Gradle 生命周期任务(clean/assemble/check)链接你想要运行的脚本,就是这样。以下是 Gradle 5.4 和 NPM 下的典型用法,摘自文档:

// 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'
}
Run Code Online (Sandbox Code Playgroud)

你会注意到:

  • 与 相反frontend-maven-plugin,没有声明/配置来触发 Gradle 的前端构建,因为它已经开箱即用。Node/NPM/Yarn 的下载、安装不需要声明/配置——除了版本号,以及构建任务。只需提供 NPM/Yarn 命令行来清理/组装/检查您的前端。
  • Node 的最低支持版本应为6.2.1. 因此,您的初始配置4.2.4将需要迁移 Node.js。
  • 该插件不支持 Bower,我认为将来不会支持它,因为 Bower 现在鼓励迁移到 Yarn。您可以在 Bower 的网站上找到迁移指南。
  • 该插件不支持使用特定的 NPM 版本。NPM 现在与 Node 打包在一起,该插件使用嵌入在下载的 Node 发行版中的版本。

问候