java - 如果 python 脚本出现任何错误,如何使 Maven 构建失败
问题描述
我在 maven 项目中使用 python 脚本,如果 python 脚本出现任何错误,我希望构建失败并显示正确的错误消息。
插件里有什么东西。如果python出错,我们可以从哪里构建失败并显示日志记录错误
这是我的 pom.xml
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<configuration>
<executable>python</executable>
<workingDirectory>src/main/resources/</workingDirectory>
<arguments>
<argument>my.py</argument>
</arguments>
</configuration>
<id>python_build</id>
<phase>generate-resources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
这是我的python脚本my.py
import logging
name = "Amit"
age = 24
if name != "Amit":
logging.error("name is not matching")
if age != 24:
logging.error("age is not matching")
解决方案
exit
如果要引发错误,请添加:
import logging
name = "Amit"
age = 24
if name != "Amit":
logging.error("name is not matching")
exit(1)
if age != 24:
logging.error("age is not matching")
exit(1)
推荐阅读
- javascript - JavaScript 检查对象是否是具有特定值的数组
- vba - 在excel公式中添加$?
- php - 使用 AWS SES 发送批量电子邮件
- angularjs - 如何将 data-plugin="timepicker" 值传递给 angularJS 中的控制器
- function - 使用一个附加函数在 FORTRAN 中未定义的引用
- r - 在 R 中使用 write_xlsx
- c++ -
必须是先前定义的类或结构 - react-native - 是否可以让嵌套的反应导航控制屏幕的一部分?
- puppet - r10k puppetfile 安装挂起/卡住
- sql-server - 类未注册 sql server management studio