Example usage for org.apache.maven.model.building ModelBuildingRequest VALIDATION_LEVEL_MINIMAL

List of usage examples for org.apache.maven.model.building ModelBuildingRequest VALIDATION_LEVEL_MINIMAL

Introduction

In this page you can find the example usage for org.apache.maven.model.building ModelBuildingRequest VALIDATION_LEVEL_MINIMAL.

Prototype

int VALIDATION_LEVEL_MINIMAL

To view the source code for org.apache.maven.model.building ModelBuildingRequest VALIDATION_LEVEL_MINIMAL.

Click Source Link

Document

Denotes minimal validation of POMs.

Usage

From source file:org.xwiki.contrib.maven.MavenPackagerUtils.java

License:Open Source License

/**
 * Build without processing any plugin the maven project of an artifact, and return it.
 *
 * @param artifact the artifact/*w  w  w . ja v  a 2  s. c  o  m*/
 * @return the maven project of this artifact
 * @throws MojoExecutionException if the build fails
 */
public MavenProject getMavenProject(Artifact artifact) throws MojoExecutionException {
    if (artifact == null) {
        return null;
    }

    try {
        ProjectBuildingRequest request = new DefaultProjectBuildingRequest(
                this.session.getProjectBuildingRequest())
                        // We don't want to execute any plugin here
                        .setProcessPlugins(false)
                        // It's not this plugin job to validate this pom.xml
                        .setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL)
                        // Use the repositories configured for the built project instead of the default Maven ones
                        .setRemoteRepositories(
                                this.session.getCurrentProject().getRemoteArtifactRepositories());
        // Note: build() will automatically get the POM artifact corresponding to the passed artifact.
        ProjectBuildingResult result = this.projectBuilder.build(artifact, request);
        return result.getProject();
    } catch (ProjectBuildingException e) {
        throw new MojoExecutionException(String.format("Failed to build project for [%s]", artifact), e);
    }
}