#maven #maven-antrun-plugin
#maven #maven-antrun-plugin
Вопрос:
Я пытаюсь использовать три плагина maven одновременно, но получаю ошибку при выполнении. Моя цель — прочитать все свойства среды, которые будут размещены в папке src, например application-sit.properties .. и т.д.
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.config</groupId>
<artifactId>config-poc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>config-poc</name>
<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/config/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>iterator-maven-plugin</artifactId>
<version>0.5.1</version>
<executions>
<execution>
<id>moving property file</id>
<phase>initialize</phase>
<goals>
<goal>iterator</goal>
</goals>
<configuration>
<items>
<item>sit</item>
<item>uat</item>
</items>
<pluginExecutors>
<pluginExecutor>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
</plugin>
<goal>read-project-properties</goal>
<configuration>
<files>
<file>${project.basedir}/config/resources/environments/common.properties</file>
<file>${project.basedir}/config/resources/environments/@item@.properties</file>
</files>
</configuration>
</pluginExecutor>
<pluginExecutor>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
</plugin>
<goal>copy-resources</goal>
<configuration>
<outputDirectory>${project.build.outputDirectory}/config/${item}/</outputDirectory>
<resources>
<resource>
<directory>${project.build.outputDirectory}</directory>
<filtering>false</filtering>
<include>*.properties</include>
</resource>
</resources>
</configuration>
</pluginExecutor>
</pluginExecutors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Получение ошибки ниже во время выполнения выглядит так, как будто плагин read property не генерирует application.properties внутри целевой папки. Ниже приведен снимок моего проекта.
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< com.test.config:config-poc >---------------------
[INFO] Building config-poc 0.0.1-SNAPSHOT
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ config-poc ---
[INFO]
[INFO] --- iterator-maven-plugin:0.5.1:iterator (moving property file) @ config-poc ---
[INFO] ------ (sit) org.codehaus.mojo:properties-maven-plugin:1.0.0:read-project-properties
[INFO] ------ (sit) org.apache.maven.plugins:maven-resources-plugin:2.7:copy-resources
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:eclipseFeclipse_workspace3config-poctargetclasses
[INFO] ------ (uat) org.codehaus.mojo:properties-maven-plugin:1.0.0:read-project-properties
[INFO] ------ (uat) org.apache.maven.plugins:maven-resources-plugin:2.7:copy-resources
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:eclipseFeclipse_workspace3config-poctargetclasses
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ config-poc ---
[INFO] Installing C:eclipseFeclipse_workspace3config-pocpom.xml to C:UsersAbhishek.m2repositorycomtestconfigconfig-poc.0.1-SNAPSHOTconfig-poc-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.798 s
[INFO] Finished at: 2020-08-29T16:29:36 05:30
[INFO] ------------------------------------------------------------------------
Комментарии:
1. Пожалуйста… добавляйте ошибки в виде текста, не фотографируйте свой экран…
2. Вот моя ошибка
3. Где ваша ошибка? Вы не отредактировали вопрос.
4. @JFabianMeier Пожалуйста, найдите журнал ошибок
5. Переформатируйте pom.xml ; удалите пустые строки и т.д. лучшим примером может быть проект на github. Кроме того, вопрос в том, почему вам нравится использовать iterator-maven-plugin? Какую проблему вы пытаетесь решить?
Ответ №1:
Приведенная ниже структура pluginExecutor решит вашу проблему.
<pluginExecutor>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<goal>copy-resources</goal>
<configuration>
<outputDirectory>${project.build.outputDirectory}/${item}/</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/config/resources/templates</directory>
<filtering>false</filtering>
<include>application.properties</include>
</resource>
</resources>
</configuration>