在maven中更改资源的目标文件夹
changing destination folder of resources in maven
我从 doc 中复制粘贴了以下片段到我的 pom.xml
<plugin>
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/resources</outputDirectory>
<resources>
<resource>
<directory>${basedir}/template</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
但是当我尝试触发部署时收到以下消息:
$ mvn resources:copy-resources
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< org.test:myproject >------------------------
[INFO] Building myproject-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:copy-resources (default-cli) @ myproject ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.440 s
[INFO] Finished at: 2021-12-26T12:30:59+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:copy-resources (default-cli) on project myproject: The parameters 'resources', 'outputDirectory' for goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:copy-resources are missing or invalid -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException
这是我的目录结构:
./resources
./template
./template/test.txt
./pom.xml
如何更改资源的目标文件夹?为什么maven没有解析插件中的配置指令?
执行特定 Maven 目标的完整命令语法是:
mvn <plugin>:<goal>@<executionId>
不指定executionId时,默认等于default-cli
。
现在你执行 mvn resources:copy-resources
相当于 mvn resources:copy-resources@default-cli
但你的 pom.xml
没有为这个目标定义这个执行 ID。所以它抱怨一些参数丢失并且没有配置好。
当你定义执行 id 为 copy-resources
时,这意味着你应该执行 :
mvn resources:copy-resources@copy-resources
或者当您将此目标绑定到 validate
阶段时,这意味着您也可以通过以下方式简单地执行它:
mvn validate
我从 doc 中复制粘贴了以下片段到我的 pom.xml
<plugin>
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/resources</outputDirectory>
<resources>
<resource>
<directory>${basedir}/template</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
但是当我尝试触发部署时收到以下消息:
$ mvn resources:copy-resources
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< org.test:myproject >------------------------
[INFO] Building myproject-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:copy-resources (default-cli) @ myproject ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.440 s
[INFO] Finished at: 2021-12-26T12:30:59+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:copy-resources (default-cli) on project myproject: The parameters 'resources', 'outputDirectory' for goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:copy-resources are missing or invalid -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException
这是我的目录结构:
./resources
./template
./template/test.txt
./pom.xml
如何更改资源的目标文件夹?为什么maven没有解析插件中的配置指令?
执行特定 Maven 目标的完整命令语法是:
mvn <plugin>:<goal>@<executionId>
不指定executionId时,默认等于default-cli
。
现在你执行 mvn resources:copy-resources
相当于 mvn resources:copy-resources@default-cli
但你的 pom.xml
没有为这个目标定义这个执行 ID。所以它抱怨一些参数丢失并且没有配置好。
当你定义执行 id 为 copy-resources
时,这意味着你应该执行 :
mvn resources:copy-resources@copy-resources
或者当您将此目标绑定到 validate
阶段时,这意味着您也可以通过以下方式简单地执行它:
mvn validate