How do I obtain a fully resolved Model of a pom file?

前端 未结 6 586
时光取名叫无心
时光取名叫无心 2021-01-30 11:40

How do I obtain a fully resolved Model of a pom file?

This is basically a rephrasing of How can i programmaticaly build the effective model of a pom file?

I\'m b

6条回答
  •  你的背包
    2021-01-30 12:33

    Romain provided the good answer above, but it was using a deprecated class that was removed from maven 3.x The updated version is this :

    @Parameter( defaultValue = "${project}", readonly = true )
    private MavenProject project;
    
    @Component
    private RepositorySystem repositorySystem;
    
    @Component
    private ProjectBuilder mavenProjectBuilder;
    
    @Parameter( defaultValue = "${session}", readonly = true )
    private MavenSession session;
    
    private MavenProject getMavenProject(String groupId, String artifactId, String version) throws ProjectBuildingException {
    
        Artifact pomArtifact = repositorySystem.createProjectArtifact(groupId, artifactId, version);
        ProjectBuildingResult build = mavenProjectBuilder.build(pomArtifact, session.getProjectBuildingRequest());
    
        return build.getProject();
    
    }
    

    A working example is in the hierarchy-maven-plugin

提交回复
热议问题