简体   繁体   English

如果依赖项无效,如何使项目失败

[英]How to fail a project if dependencies are invalid

I'm working on a maven build pipeline.我正在研究 maven 构建管道。 Currently I'm facing the problem that a maven project is still building if a dependency is invalid.目前我面临的问题是,如果依赖项无效,maven 项目仍在构建中。 I think everyone know that warning in the log:我想每个人都知道日志中的警告:

[WARNING] The POM for is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details. [警告] POM 无效,传递依赖项(如果有)将不可用,请启用调试日志以获取更多详细信息。

I would like to fail the project instead of a warning because in a big build pipeline its hard to find.我想使项目失败而不是警告,因为在大型构建管道中很难找到。

I looked into the code: The warning happens in maven-core because of an EventType.ARTIFACT_DESCRIPTOR_INVALID.我查看了代码:由于 EventType.ARTIFACT_DESCRIPTOR_INVALID,警告发生在 maven-core 中。

In the DefaultArtifactDescriptorReader I found that during building the effective model the ModelBuildingException is catched.在 DefaultArtifactDescriptorReader 中,我发现在构建有效的 model 期间捕获了 ModelBuildingException。 There is a ArtifactDescriptorPolicy.有一个 ArtifactDescriptorPolicy。 Based on that a exception will be added or only the EventType.ARTIFACT_DESCRIPTOR_INVALID is fired (see invalidDescriptor()).基于此,将添加异常或仅触发 EventType.ARTIFACT_DESCRIPTOR_INVALID(请参阅 invalidDescriptor())。

          model = modelBuilder.build( modelRequest ).getEffectiveModel();
    }
    catch ( ModelBuildingException e )
            {
                for ( ModelProblem problem : e.getProblems() )
                {
                    if ( problem.getException() instanceof UnresolvableModelException )
                    {
                        result.addException( problem.getException() );
                        throw new ArtifactDescriptorException( result );
                    }
                }
                invalidDescriptor( session, trace, a, e );
                if ( ( getPolicy( session, a, request ) & ArtifactDescriptorPolicy.IGNORE_INVALID ) != 0 )
                {
                    return null;
                }
                result.addException( e );
                throw new ArtifactDescriptorException( result );
            }

I didn't found any option to configure the ArtifactDescriptorPolicy.我没有找到任何配置 ArtifactDescriptorPolicy 的选项。 I expect that the ArtifactDescriptorPolicy.STRICT would solve my problem.我希望 ArtifactDescriptorPolicy.STRICT 能解决我的问题。 Does anyone knows more about that problem?有谁知道更多关于这个问题的信息?

I think you're a bit ahead of the curve.我觉得你有点超前了。 There is a feature (new switch) in Maven 4 called --fail-on-severity or -fos that does exactly this: fail the build on a specific severity. Maven 4中有一个名为--fail-on-severity-fos的功能(新开关)正是这样做的:在特定严重性上使构建失败。

$ mvn -fos WARN clean install

If you don't mind being on the bleeding edge, you could install it and give it a go.如果您不介意处于最前沿,您可以安装它并给它一个 go。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM