Maven资源插件:如果目录不存在,构建不会失败 [英] Maven Resources Plugin: Build won't fail if directory doesn't exists

查看:92
本文介绍了Maven资源插件:如果目录不存在,构建不会失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的pom.xml中,我具有以下配置:
构建插件:

In my pom.xml... I have the following configurations:
Build plugin:

<plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <executions>
    <execution>
      <id>copy-resources</id>
      <phase>validate</phase>
      <goals>
        <goal>copy-resources</goal>
      </goals>
      <configuration>
        <outputDirectory>${build.directory}/classes/static/</outputDirectory >
        <resources>
          <resource>
            <!-- this is defined in profiles -->
            <directory>${myResourceFolder}</directory>
          </resource>
        </resources>
      </configuration>
    </execution>
  </executions>
</plugin>


配置文件定义:


Profiles definition:

<profiles>
  <profile>
      <id>development</id>
      <activation>
        <!-- this profile is active by default -->
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <myResourceFolder>/myDevelopmentFolder</myResourceFolder>
      </properties>
  </profile>
  <profile>
      <id>production</id>
      <properties>
        <myResourceFolder>${env.MY_PRODUCTION_FOLDER}</myResourceFolder>
      </properties>
  </profile>
</profiles>


$ {myResourceFolder}在不同的配置文件中定义的可以是:


Where ${myResourceFolder} is defined in different profiles which can either be:

  • /myDevelopmentFolder
  • MY_PRODUCTION_FOLDER

其中"/myDevelopmentFolder"是我的本地开发文件夹,"MY_PRODUCTION_FOLDER"是在生产版本中定义为环境变量的任何文件夹.
这些配置可以很好地编译.
但是我想实现的是,如果缺少此文件夹中的任何一个,

where "/myDevelopmentFolder" is my local development folder and "MY_PRODUCTION_FOLDER" is any folder defined as an environment variable in the production build.
These configurations compiles fine.
But I wanted to achieve is that, if any of this folder is missing,

maven-resources-plugin应该失败.

maven-resources-plugin should fail.


无论如何,在Maven中可以实现这一目标吗?


Is there anyway of achieving this in Maven?

谢谢,
阿塔尼斯(Artanis)

Thanks,
Artanis

推荐答案

1)首先,我认为为不同的环境构建不同的二进制文件是一种不好的方法.最好捆绑所有资源,只在运行时使用适当的资源

1) First of all, I think it is bad approach to build different binaries for difference environments. Better to bundle all resources and just use proper resources at runtime

2)如果您仍然想采用这种错误的方式,则可以尝试对丢失的文件进行配置文件激活( https://maven.apache.org/guides/introduction/introduction-to-profiles.html ).此构建破坏者"配置文件应以某种方式破坏构建.例如,它可能包含Maven Enforcer插件( https://maven. apache.org/enforcer/maven-enforcer-plugin/usage.html ),它会禁止带有解释性消息的资源插件

2) If you still want go this wrong way then you can try profile activation on missing file (https://maven.apache.org/guides/introduction/introduction-to-profiles.html). This "build-breaker" profile should break build somehow. For example, it may include Maven Enforcer plugin (https://maven.apache.org/enforcer/maven-enforcer-plugin/usage.html) which bans resource plugin with explanatory message

这篇关于Maven资源插件:如果目录不存在,构建不会失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆