属性-maven-插件:加载属性文件时出错

2023-11-27

我想将 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-文件?

EDIT

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

这是设计使然。项目定义 必须是独立的,否则 如果被引用则不再完整 作为一部分从其他地方 传递依赖


Your configuration元素定义在一个内部execution因此适用于此execution only.

所以要么打电话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

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


Update:我自己做了一个测试,确实使用了以下 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>

Running 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/resources
Downloading: 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/resources
Downloading: 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.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

属性-maven-插件:加载属性文件时出错 的相关文章

随机推荐

  • IOS 5 如何更改导航栏中后退按钮的颜色?

    I want to change the color of back button of a navigation bar to make it look like this Set the backBarButtonItem s tint
  • Javascript 中与 64 位整数的按位 AND

    我正在寻找一种在 JavaScript 中对 64 位整数执行按位 AND 的方法 JavaScript 会将其所有双精度值转换为带符号的 32 位整数以执行按位运算 详细信息在这里 Javascript 将所有数字表示为 64 位双精度
  • 在 QMake 中设置 RPATH 顺序

    我有一个 Linux Qt 程序 我希望它优先使用可执行文件目录中的 动态 Qt 库 如果存在 否则使用系统的 Qt 库 RPATH 来救援 我将此行添加到qmake的 pro 文件 QMAKE LFLAGS Wl rpath ORIGIN
  • Visual Studio 2010 无法识别 .cshtml 文件

    我最近重新安装了 Visual Studio 2010 因为这样做我不知道如何让它再次识别 cshtml 文件 我尝试安装 MVC 3 但它说它已经安装了 基本上当我打开 cshtml 文件时Visual Studio 它们没有代码高亮或智
  • DRF:如何将 django-rest-framework-jwt 集成到 Djoser

    我计划构建一个应用程序Django 休息框架 我更感兴趣的是使用Django Rest Framework JWT认证机制比Session or Token认证机制 但所有其他包都喜欢Django Rest Auth and Djoser
  • 如何获取URI的最后一个路径段

    我有一个字符串作为输入URI 如何获得最后一个路径段 在我的例子中是一个 id 这是我输入的网址 String uri http base path some segment id 我必须获得我尝试过的 id String strId ht
  • 如何在iOS中获取CSRF令牌?

    因此 我尝试将表单数据发布到我同事的网站 以便从我的 iPhone 应用程序登录 简单的用户名和密码 但是 我似乎需要 CSRF 令牌才能发帖 我对此做了很多研究 并且从中我可以从csrftoken cookie 我在这里读到 https
  • 在 Windows/Apache 上设置 Python?

    我想要一个简单的 Python hello world 网页脚本在 Windows Vista Apache 上运行 但遇到了不同的障碍 我用的是WAMP 我已经安装了mod python并且模块显示 但我不太确定我应该做什么 例如http
  • 反应式表单数组 - 推送新元素时避免验证错误

    我有一个由单个表单数组组成的表单组 ngOnInit this deviceDetailsFormGroup this formBuilder group deviceDetails this formBuilder array this
  • 如何禁用纸浆的计算日志

    我在 python 中使用 pulp 和 GUROBI 来解决一些优化问题 例如 GUROBI的计算日志是 Optimize a model with 12 rows 25 columns and 39 nonzeros Coefficie
  • 从地址字符串中提取邮政编码

    我有一些完整的地址 例如 addr1 5285 KEYES DR KALAMAZOO MI 49004 2613 addr2 PO BOX 35 COLFAX LA 71417 35 addr3 64938 MAGNOLIA LN APT
  • 如何避免 wkhtmltopdf 表格行内分页

    我正在从 html 页面生成 pdf 报告一张桌子 我在用wkhtml转pdf为目的 当pdf生成时在 tr 标记中的任意位置中断 我想避免它 2015 年 9 月 17 日更新 检查您正在使用的版本 据说 wkhtmltopdf 0 12
  • dispatchEvent 不触发 jQuery.on() 事件监听器

    我有以下触发自定义命名事件的代码 elem addEventListener click function event event preventDefault Do some processing stuff var event new
  • 警告:类加载器在 Android Studio 2.1.2 中引用了未知路径

    我是 Android 和 Android Studio 的新手 我在 Android Studio 中创建了一个 HelloWorld 项目 当我在设备上运行该应用程序时 我收到以下警告 如何修复这些警告 6 15 11 21 22 287
  • 使用scikit-learn分类为多个类别

    我正在尝试使用 scikit learn 的监督学习方法之一将文本片段分类为一个或多个类别 我尝试过的所有算法的预测函数都只返回一个匹配项 例如我有一段文字 Theaters in New York compared to those in
  • 如何将数字字符串排序为数字?

    如果你有这样的字符串 file 0 file 1 file 2 file 3 file 4 file 5 file 6 file 11 如何对它们进行排序 以便 file 11 不会出现在 file 1 之后 而是出现在 file 6 之后
  • List<> 元素是否按顺序位于堆状数组中?

    我正在学习C 基本上知道数组和数组之间的区别List最后一个是通用的 可以动态增长 但我想知道 are List元素顺序位于堆状数组中 还是每个元素 随机 位于不同位置 如果这是真的 这是否会影响内存访问和数据检索的速度 如果这是真的 这就
  • 函数内的“static”关键字?

    我正在查看 Drupal 7 的源代码 发现了一些我以前没有见过的东西 我在 php 手册中做了一些初步的查找 但它没有解释这些示例 关键字是什么static对函数内的变量做什么 function module load all boots
  • Vb.net随机数生成器多次生成相同的数字

    我有这个程序从文件中生成名字和姓氏 当我运行该程序时 我在三个文本框中输入信息 前两个是工资低和高 salary1 text salary2 text 最后一个是我想要的 份数 copies text 当我在文本中输入诸如10之类的数字时它
  • 属性-maven-插件:加载属性文件时出错

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