gpt4 book ai didi

java - 如果 python 脚本出现任何错误,如何使 Maven 构建失败

转载 作者:行者123 更新时间:2023-12-01 18:13:04 25 4
gpt4 key购买 nike

我在 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)

关于java - 如果 python 脚本出现任何错误,如何使 Maven 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60427870/

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