从Maven迁移frontend-maven-plugin到gradle [英] Migrate frontend-maven-plugin from maven to gradle
问题描述
我的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>
现在,我需要将其迁移到gradle
中,但是找不到如何执行该操作的示例.成绩迁移工具仅翻译依赖项,而不翻译插件.有一些示例,如何在gradle
中使用frontend-maven-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
?
推荐答案
您可能找不到有关如何在Gradle中使用frontend-maven-plugin
的任何示例,因为它专用于Maven.但是您可以看看 Siouan Frontend Gradle插件,它是与之等效的解决方案Gradle,并允许(从官方网站):
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):
将您的前端NPM/纱线构建集成到Gradle中.
Integrate your frontend NPM/Yarn build into Gradle.
用法和配置似乎与您的Maven配置接近.在build.gradle
文件中定义Node/NPM/Yarn版本,根据Gradle生命周期任务(清理/组装/检查)链接要运行的脚本,仅此而已.以下是Gradle 5.4和NPM的典型用法,摘自文档:
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'
}
您会注意到:
- 与
frontend-maven-plugin
相反,没有声明/配置来触发Gradle的前端构建,因为它已经提供了开箱即用的功能.下载,安装Node/NPM/Yarn不需要声明/配置-除了版本号和构建任务外.只需提供NPM/Yarn命令行即可清理/组装/检查您的前端. - Node的最低支持版本应为
6.2.1
.因此,使用4.2.4
进行的初始配置将需要迁移Node. - 该插件不支持Bower,并且我不认为将来会支持该插件,因为Bower现在鼓励迁移到Yarn.您可以在Bower网站上找到迁移指南.
- 该插件不支持使用特定的NPM版本. NPM现在与Node打包在一起,该插件使用下载的Node发行版本中嵌入的版本.
- 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 with4.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.
致谢
这篇关于从Maven迁移frontend-maven-plugin到gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!