简体   繁体   English

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

[英]Migrate frontend-maven-plugin from maven to gradle

I have a com.github.eirslett:frontend-maven-plugin in my maven project. 我的maven项目中有一个com.github.eirslett:frontend-maven-plugin

<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. 现在我需要将它迁移到gradle但我找不到示例如何做到这一点。 Grade migration tool translates only dependencies but not plugins. 成绩迁移工具仅转换依赖项,但不转换插件。 Is there some examples, how can I use frontend-maven-plugin in gradle ? 是否有一些例子,如何在gradle使用frontend-maven-plugin

Google found the Gradle Frontend Plugin for me. Google为我找到了Gradle Frontend插件 The plugin description simply says: 插件描述简单地说:

Set of tasks which wraps common frontend-tools and provide its binaries. 包含常见前端工具并提供其二进制文件的任务集。

The documentation (as at March 2016) describes the 4 tasks ( installnode , npm , grunt and gulp ) and examples of their use. 文档(截至2016年3月)描述了4个任务( installnodenpmgruntgulp )及其使用的例子。


An alternative (provided by @Timofei) is the Gradle Plugin for Node . 替代方案(由@Timofei提供)是节点Gradle插件 The description says: 描述说:

This plugin enables you to use NodeJS-based technologies as part of your build without having NodeJS installed locally on your system. 此插件使您可以将基于NodeJS的技术用作构建的一部分,而无需在系统上本地安装NodeJS。 It integrates Gradle with NodeJS, Yarn, Grunt, and Gulp. 它将Gradle与NodeJS,Yarn,Grunt和Gulp集成在一起。

(Edited for clarity) (为清晰起见编辑)

Note that this plugin's Github repo is active while the previous one hasn't had any commits in the last two years. 请注意,此插件的Github存储库处于活动状态,而前一个存储库在过去两年中没有任何提交。

You may not find any example on how to use the frontend-maven-plugin in Gradle, as it is dedicated to Maven. 您可能找不到任何关于如何在Gradle中使用frontend-maven-plugin示例,因为它专用于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): 但是你可以看看Siouan Frontend Gradle插件 ,它是Gradle的等效解决方案,允许(来自官方网站):

Integrate your frontend NPM/Yarn build into Gradle. 将您的前端NPM / Yarn构建集成到Gradle中。

The usage and configuration seems close to your Maven configuration. 使用情况和配置似乎与Maven配置相近。 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. build.gradle文件中定义Node / NPM / Yarn版本,根据Gradle生命周期任务(清理/汇编/检查)链接要运行的脚本,这就是全部。 Below is a typical usage under Gradle 5.4 with NPM, taken from the docs: 以下是使用NPM的Gradle 5.4下的典型用法,取自文档:

// 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. frontend-maven-plugin相反,没有声明/配置来触发使用Gradle构建前端,因为它已经开箱即用。 The download, installation of Node/NPM/Yarn requires no declaration/configuration - except the version numbers, as well as the build tasks. Node / NPM / Yarn的下载,安装不需要声明/配置 - 除了版本号以及构建任务。 Just provide the NPM/Yarn command line to clean/assemble/check your frontend. 只需提供NPM / Yarn命令行来清理/组装/检查您的前端。
  • The mimimum supported version of Node shall be 6.2.1 . Node的最小支持版本应为6.2.1 So your initial configuration with 4.2.4 will require to migrate Node. 因此, 4.2.4的初始配置将需要迁移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. 该插件不支持Bower,我不认为它将来会得到支持,因为Bower现在鼓励迁移到Yarn。 You'll find a migration guide on Bower's website. 您可以在Bower的网站上找到迁移指南。
  • The plugin does not support the use of a specific NPM release. 该插件不支持使用特定的NPM版本。 NPM being now packaged with Node, the plugin uses the version embedded in the downloaded Node distribution. NPM现在与Node一起打包,插件使用下载的Node分发中嵌入的版本。

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 frontend-maven-plugin执行两次 - frontend-maven-plugin executed twice 使用frontend-maven-plugin构建Maven多模块项目时出错 - Error building maven multi module project with frontend-maven-plugin Maven 错误 Pom.xml - frontend-maven-plugin - Maven Error Pom.xml - frontend-maven-plugin frontend-maven-plugin 不能“凉亭安装” - frontend-maven-plugin can't "bower install" 使用eirslett:frontend-maven-plugin在gitlab.com上运行maven build - run maven build on gitlab.com with eirslett:frontend-maven-plugin Angular7 + Maven与IBM Websphere错误(frontend-maven-plugin:1.0:npm(npm安装失败)) - Angular7 + maven with IBM websphere error (frontend-maven-plugin:1.0:npm (npm install fail)) 问题在“<execution> &quot; 标签试图将前端 Maven 插件添加到 java proyect - Problem in "<execution>" tag trying to add frontend-maven-plugin to java proyect 当文件确实存在时,使用 frontend-maven-plugin 生成资源会为 semver 抛出 NoSuchFileException - Generating resources with frontend-maven-plugin throws NoSuchFileException for semver when the file does exist 未能执行目标:com.github.eirslett:frontend-maven-plugin:0.0.27:npm - Failed to execute goal: com.github.eirslett:frontend-maven-plugin:0.0.27:npm 运行 npm 构建时无法访问 vue.js 前端(frontend-maven-plugin 和 spring-boot 后端) - Cannot access vue.js frontend when running npm build (frontend-maven-plugin and spring-boot backend)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM