gpt4 book ai didi

maven-2 - 属性-maven-插件 : Error loading properties-file

转载 作者:行者123 更新时间:2023-12-02 08:38:45 25 4
gpt4 key购买 nike

我想将 pom.xml 中的所有属性提取到属性文件中。这些是常见的属性,如依赖版本、插件版本和目录。我正在使用properties-maven-plugin,但它没有按照我想要的方式工作。

我的 pom.xml 的重要部分:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/pom.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>

现在,当我运行“mvnproperties:read-project-properties”时,出现以下错误:

[INFO] One or more required plugin parameters are invalid/missing for 'properties:read-project-properties'

[0] Inside the definition for plugin 'properties-maven-plugin' specify the following:

<configuration>
...
<files>VALUE</files>
</configuration>.

pom.properties 文件与 pom.xml 位于同一目录中。我该怎么做才能让properties-maven-plugin读取我的properties-file?

编辑

我在 http://jira.codehaus.org/browse/MOJO-1523 提交了一个问题。它已被关闭为“不是错误”,原因是:

It's by design. The project definition has to be self-contained, otherwise it is no longer complete if it is refered from elsewhere as part of the transitive deps.

最佳答案

您的configuration元素定义在 execution 内因此适用于此execution仅有的。

所以要么调用 mvn initialize (或 initialize 之后的阶段)使用 configuration您当前的execution捆绑。

或者使用全局 configuration :

  <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<configuration>
<files>
<file>etc/config/dev.properties</file>
</files>
</configuration>
...
</plugin>

然后调用

mvn properties:read-project-properties

但这在这个插件的特定情况下没有多大意义(您希望属性在构建期间可用),因此这给您留下了第一个解决方案。

<小时/>

更新:我自己做了一个测试,确实使用了以下 POM:

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>Q2664362</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>etc/config/dev.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

正在运行mvn test不起作用:maven 将尝试下载 junit:jar:${junit.version} (即它不使用属性的值),这显然会失败。

$ mvn test[INFO] Scanning for projects...[INFO] ------------------------------------------------------------------------[INFO] Building SO - Q2664362 - maven-properties-plugin demo[INFO]    task-segment: [test][INFO] ------------------------------------------------------------------------[INFO] [properties:read-project-properties {execution: default}][INFO] [resources:resources {execution: default-resources}][INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory /home/pascal/Projects/stackoverflow/Q2664362/src/main/resourcesDownloading: http://repo1.maven.org/maven2/junit/junit/${junit.version}/junit-${junit.version}.pom[INFO] Unable to find resource 'junit:junit:pom:${junit.version}' in repository central (http://repo1.maven.org/maven2)[INFO] [compiler:compile {execution: default-compile}][INFO] Nothing to compile - all classes are up to date[INFO] [resources:testResources {execution: default-testResources}][INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory /home/pascal/Projects/stackoverflow/Q2664362/src/test/resourcesDownloading: http://repo1.maven.org/maven2/junit/junit/${junit.version}/junit-${junit.version}.jar[INFO] Unable to find resource 'junit:junit:jar:${junit.version}' in repository central (http://repo1.maven.org/maven2)[INFO] ------------------------------------------------------------------------[ERROR] BUILD ERROR[INFO] ------------------------------------------------------------------------[INFO] Failed to resolve artifact....

奇怪的是,依赖项的下载发生在 properties:read-project-properties 之后。我不确定,但这听起来像是一个错误,您应该打开 an issue .

关于maven-2 - 属性-maven-插件 : Error loading properties-file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2664362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com