当资源过滤无法找到属性时,Maven会警告或失败目标(Maven warn or fail goal when resource filtering cannot find a property)
我开始研究一个记录不完整的Maven项目。 我已经为项目设置了我的配置文件,但我可能会或可能不会缺少资源过滤期间使用的属性定义。 默认情况下,如果未在筛选文件中定义属性,则变量名称将保留在复制的资源中,Maven将以静默方式继续。
在这种情况下,有没有办法迫使Maven快速失败?
作为一个最小的例子,拿这个pom,
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>my-app</name> <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build> <profiles> <profile> <id>production</id> <properties> <foo>Craig</foo> </properties> </profile> </profiles> </project>
并有一个资源来过滤:
echo 'Hello, my name is ${foo}!' > src/main/resources/test
然后运行
mvn clean install -Pproduction
生成一个文件,上面写着Hello, my name is Craig!
运行mvn clean install
会生成一个说Hello, my name is ${foo}!
的文件Hello, my name is ${foo}!
。所以我的问题是; 在第二种情况下如何强制Maven失败?
I am starting to work on a poorly documented Maven project. I have set up my profile for the project but I may or may not be missing property definitions that used during resource filtering. By default, if a property is not defined in a filtered file, the variable name is left in the copied resource and Maven continues silently.
Is there a way to force Maven to fast-fail in this case?
As a minimal example, take this pom,
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>my-app</name> <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build> <profiles> <profile> <id>production</id> <properties> <foo>Craig</foo> </properties> </profile> </profiles> </project>
And have a resource to filter:
echo 'Hello, my name is ${foo}!' > src/main/resources/test
Then running
mvn clean install -Pproduction
produces a file that saysHello, my name is Craig!
while runningmvn clean install
produces a file that saysHello, my name is ${foo}!
.So my question is; how do I force Maven to fail in the second case?
原文:https://stackoverflow.com/questions/17732618
最满意答案
在您的语言环境中设置“name_user”的翻译。 您可以更改字段的名称以及错误消息的确切用词。
# config/locales/en.yml en: activerecord: attributes: user: name_user: "First name" errors: models: user: attributes: name_user: blank: "is required"
您可以扩展它以用于其他字段甚至其他模型......
# config/locales/en.yml en: activerecord: attributes: user: name_user: "First name" surname_user: "Last name" department: created_year: "Year established" errors: models: user: attributes: name_user: blank: "is required"
set up a translation for "name_user" in your locales. You can change both the name of the field and what the exact wording of the error message should be.
# config/locales/en.yml en: activerecord: attributes: user: name_user: "First name" errors: models: user: attributes: name_user: blank: "is required"
You can extend it for additional fields and even other models...
# config/locales/en.yml en: activerecord: attributes: user: name_user: "First name" surname_user: "Last name" department: created_year: "Year established" errors: models: user: attributes: name_user: blank: "is required"
相关问答
更多-
打开表格,在窗口的T-SQL部分突出显示表名,单击SQL菜单,然后选择重构和重命名。 您可能想在预览时查看更改,看看会受到什么影响。 Open the table, highlight the table name in the T-SQL portion of the window, click the SQL menu, then choose Refactor and Rename. You probably want to preview changes while you're at it to ...
-
重命名Oracle表或视图(Rename Oracle Table or View)[2023-05-25]
ALTER TABLE mytable RENAME TO othertable 在Oracle 10g也: RENAME mytable TO othertable ALTER TABLE mytable RENAME TO othertable In Oracle 10g also: RENAME mytable TO othertable -
无法在RedShift中重命名表(Can't rename table in RedShift)[2023-02-06]
发现问题 - 我的python代码中的错误 - 它写成'tbl_Old'(而不是'tbl_old')。 Problem found - bug in my python code - it was written 'tbl_Old' (instead of 'tbl_old'). -
ALTER TABLE foo RENAME TO bar ALTER TABLE foo RENAME TO bar
-
米哈伊, 这是一个很好的问题。 当您手动执行表维护并且希望移动/创建/重命名表而不影响现有的依赖对象时,您正在搜索的功能非常有用。 对你的问题的简短回答是“不”。 在Redshift中无法阻止此行为。 您无法在“ALTER TABLE”语句或“CREATE VIEW”语句中执行任何操作,这会阻止在基础表更改时更改从属视图。 但 您可以在更改名称之前轻松获取视图的DDL,并且可以在准备好后重新运行DDL,这样您的视图就会指向正确的位置。 以下SQL将显示特定表的所有相关视图,并生成以重新创建每个相应的视图。 ...
-
在c#中重命名表(Rename a table in c#)[2022-03-16]
你可以使用这个:sp_rename exec sp_rename'schema.old_test','new_your_new_table_name' You can use this: sp_rename exec sp_rename 'schema.old_test', 'new_your_new_table_name' -
在sqlite中重命名表(Rename table in sqlite)[2022-09-09]
尝试这个: ALTER TABLE orig_table_name RENAME TO tmp_table_name; Try execSQL instead of rawQuery like: ourDatabase.execSQL("ALTER TABLE " + original_table_name + " RENAME TO " + new_table_name); -
如何在验证中重命名表(How to rename table in validates)[2023-11-18]
在您的语言环境中设置“name_user”的翻译。 您可以更改字段的名称以及错误消息的确切用词。 # config/locales/en.yml en: activerecord: attributes: user: name_user: "First name" errors: models: user: attributes: name_user: blan ... -
如何在Spring-Security中重命名表persistent_logins(How to rename the table persistent_logins in Spring-Security)[2024-01-01]
您需要编写自己的JdbcTokenRepositoryImpl实现 创建一个扩展JdbcDaoSupport并实现PersistentTokenRepository的类 在Spring Application Context Config中将此类配置为bean,然后将其设置为remember-me Spring Security Config的token-repository-ref属性 但坦率地说,我会先改变你的表命名策略。 You'll need to write your own implementa ... -
根据您编辑的答案,最快的方法是: 如果必须在列中包含默认值 ALTER TABLE {TABLENAME} ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL} CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE} [WITH VALUES] 然后从表中删除旧列。 ALTER TABLE {TABLENAME} DROP COLUMN {OLD COLUMN} 如果必须更新基于表列的计算值 禁用要更新的列的索引 在WHERE子句 ...