Class MavenProject

java.lang.Object
org.apache.maven.project.MavenProject
All Implemented Interfaces:
Cloneable

public class MavenProject extends Object implements Cloneable
The concern of the project is provide runtime values based on the model.

The values in the model remain untouched but during the process of building a project notions like inheritance and interpolation can be added. This allows to have an entity which is useful in a runtime while preserving the model so that it can be marshalled and unmarshalled without being tainted by runtime requirements.

With changes during 3.2.2 release MavenProject is closer to being immutable after construction with the removal of all components from this class, and the upfront construction taken care of entirely by the ProjectBuilder. There is still the issue of having to run the lifecycle in order to find all the compile source roots and resource directories but I hope to take care of this during the Maven 4.0 release (jvz).

  • Field Details Link icon

  • Constructor Details Link icon

    • MavenProject Link icon

      public MavenProject()
    • MavenProject Link icon

      public MavenProject(org.apache.maven.api.model.Model model)
    • MavenProject Link icon

      public MavenProject(Model model)
    • MavenProject Link icon

      public MavenProject(MavenProject project)
  • Method Details Link icon

    • getParentFile Link icon

      public File getParentFile()
    • setParentFile Link icon

      public void setParentFile(File parentFile)
    • getArtifact Link icon

      public Artifact getArtifact()
    • setArtifact Link icon

      public void setArtifact(Artifact artifact)
    • getModel Link icon

      public Model getModel()
    • getParent Link icon

      public MavenProject getParent()
      Returns the project corresponding to a declared parent.
      Returns:
      the parent, or null if no parent is declared or there was an error building it
    • setParent Link icon

      public void setParent(MavenProject parent)
    • hasParent Link icon

      public boolean hasParent()
    • getFile Link icon

      public File getFile()
    • setFile Link icon

      public void setFile(File file)
    • setPomFile Link icon

      public void setPomFile(File file)
      Sets project file without changing project basedir.
      Since:
      3.2.4
    • getBasedir Link icon

      public File getBasedir()
    • setDependencies Link icon

      public void setDependencies(List<Dependency> dependencies)
    • getDependencies Link icon

      public List<Dependency> getDependencies()
    • getDependencyManagement Link icon

      public DependencyManagement getDependencyManagement()
    • addCompileSourceRoot Link icon

      public void addCompileSourceRoot(String path)
    • addTestCompileSourceRoot Link icon

      public void addTestCompileSourceRoot(String path)
    • getCompileSourceRoots Link icon

      public List<String> getCompileSourceRoots()
    • getTestCompileSourceRoots Link icon

      public List<String> getTestCompileSourceRoots()
    • getCompileClasspathElements Link icon

      @Deprecated public List<String> getCompileClasspathElements() throws DependencyResolutionRequiredException
      Deprecated.
      This method is unreliable because it does not consider other dependency properties. See JavaPathType instead for better analysis.
      Returns the elements placed on the classpath for compilation. This method can be invoked when the caller does not support module-path.
      Throws:
      DependencyResolutionRequiredException - if an artifact file is used, but has not been resolved
    • getTestClasspathElements Link icon

      @Deprecated public List<String> getTestClasspathElements() throws DependencyResolutionRequiredException
      Deprecated.
      This method is unreliable because it does not consider other dependency properties. See JavaPathType instead for better analysis.
      Returns the elements placed on the classpath for tests. This method can be invoked when the caller does not support module-path.
      Throws:
      DependencyResolutionRequiredException - if an artifact file is used, but has not been resolved
    • getRuntimeClasspathElements Link icon

      @Deprecated public List<String> getRuntimeClasspathElements() throws DependencyResolutionRequiredException
      Deprecated.
      This method is unreliable because it does not consider other dependency properties. See JavaPathType instead for better analysis.
      Returns the elements placed on the classpath for runtime. This method can be invoked when the caller does not support module-path.
      Throws:
      DependencyResolutionRequiredException - if an artifact file is used, but has not been resolved
    • setModelVersion Link icon

      public void setModelVersion(String pomVersion)
    • getModelVersion Link icon

      public String getModelVersion()
    • getId Link icon

      public String getId()
    • setGroupId Link icon

      public void setGroupId(String groupId)
    • getGroupId Link icon

      public String getGroupId()
    • setArtifactId Link icon

      public void setArtifactId(String artifactId)
    • getArtifactId Link icon

      public String getArtifactId()
    • setName Link icon

      public void setName(String name)
    • getName Link icon

      public String getName()
    • setVersion Link icon

      public void setVersion(String version)
    • getVersion Link icon

      public String getVersion()
    • getPackaging Link icon

      public String getPackaging()
    • setPackaging Link icon

      public void setPackaging(String packaging)
    • setInceptionYear Link icon

      public void setInceptionYear(String inceptionYear)
    • getInceptionYear Link icon

      public String getInceptionYear()
    • setUrl Link icon

      public void setUrl(String url)
    • getUrl Link icon

      public String getUrl()
    • getPrerequisites Link icon

      public Prerequisites getPrerequisites()
    • setIssueManagement Link icon

      public void setIssueManagement(IssueManagement issueManagement)
    • getCiManagement Link icon

      public CiManagement getCiManagement()
    • setCiManagement Link icon

      public void setCiManagement(CiManagement ciManagement)
    • getIssueManagement Link icon

      public IssueManagement getIssueManagement()
    • setDistributionManagement Link icon

      public void setDistributionManagement(DistributionManagement distributionManagement)
    • getDistributionManagement Link icon

      public DistributionManagement getDistributionManagement()
    • setDescription Link icon

      public void setDescription(String description)
    • getDescription Link icon

      public String getDescription()
    • setOrganization Link icon

      public void setOrganization(Organization organization)
    • getOrganization Link icon

      public Organization getOrganization()
    • setScm Link icon

      public void setScm(Scm scm)
    • getScm Link icon

      public Scm getScm()
    • setMailingLists Link icon

      public void setMailingLists(List<MailingList> mailingLists)
    • getMailingLists Link icon

      public List<MailingList> getMailingLists()
    • addMailingList Link icon

      public void addMailingList(MailingList mailingList)
    • setDevelopers Link icon

      public void setDevelopers(List<Developer> developers)
    • getDevelopers Link icon

      public List<Developer> getDevelopers()
    • addDeveloper Link icon

      public void addDeveloper(Developer developer)
    • setContributors Link icon

      public void setContributors(List<Contributor> contributors)
    • getContributors Link icon

      public List<Contributor> getContributors()
    • addContributor Link icon

      public void addContributor(Contributor contributor)
    • setBuild Link icon

      public void setBuild(Build build)
    • getBuild Link icon

      public Build getBuild()
    • getResources Link icon

      public List<Resource> getResources()
    • getTestResources Link icon

      public List<Resource> getTestResources()
    • addResource Link icon

      public void addResource(Resource resource)
    • addTestResource Link icon

      public void addTestResource(Resource testResource)
    • setLicenses Link icon

      public void setLicenses(List<License> licenses)
    • getLicenses Link icon

      public List<License> getLicenses()
    • addLicense Link icon

      public void addLicense(License license)
    • setArtifacts Link icon

      public void setArtifacts(Set<Artifact> artifacts)
    • getArtifacts Link icon

      public Set<Artifact> getArtifacts()
      All dependencies that this project has, including transitive ones. Contents are lazily populated, so depending on what phases have run dependencies in some scopes won't be included. e.g. if only compile phase has run, dependencies with scope test won't be included.
      Returns:
      Set < Artifact >
      See Also:
    • getArtifactMap Link icon

      public Map<String,Artifact> getArtifactMap()
    • setPluginArtifacts Link icon

      public void setPluginArtifacts(Set<Artifact> pluginArtifacts)
    • getPluginArtifacts Link icon

      public Set<Artifact> getPluginArtifacts()
    • getPluginArtifactMap Link icon

      public Map<String,Artifact> getPluginArtifactMap()
    • setParentArtifact Link icon

      public void setParentArtifact(Artifact parentArtifact)
    • getParentArtifact Link icon

      public Artifact getParentArtifact()
    • getRepositories Link icon

      public List<Repository> getRepositories()
    • getBuildPlugins Link icon

      public List<Plugin> getBuildPlugins()
    • getModules Link icon

      public List<String> getModules()
    • getPluginManagement Link icon

      public PluginManagement getPluginManagement()
    • setRemoteArtifactRepositories Link icon

      public void setRemoteArtifactRepositories(List<ArtifactRepository> remoteArtifactRepositories)
    • getRemoteArtifactRepositories Link icon

      public List<ArtifactRepository> getRemoteArtifactRepositories()
    • setPluginArtifactRepositories Link icon

      public void setPluginArtifactRepositories(List<ArtifactRepository> pluginArtifactRepositories)
    • getPluginArtifactRepositories Link icon

      public List<ArtifactRepository> getPluginArtifactRepositories()
      Returns:
      a list of ArtifactRepository objects constructed from the Repository objects returned by getPluginRepositories.
    • getDistributionManagementArtifactRepository Link icon

      public ArtifactRepository getDistributionManagementArtifactRepository()
    • getPluginRepositories Link icon

      public List<Repository> getPluginRepositories()
    • getRemoteProjectRepositories Link icon

      public List<org.eclipse.aether.repository.RemoteRepository> getRemoteProjectRepositories()
    • getRemotePluginRepositories Link icon

      public List<org.eclipse.aether.repository.RemoteRepository> getRemotePluginRepositories()
    • setActiveProfiles Link icon

      public void setActiveProfiles(List<Profile> activeProfiles)
    • getActiveProfiles Link icon

      public List<Profile> getActiveProfiles()
    • setInjectedProfileIds Link icon

      public void setInjectedProfileIds(String source, List<String> injectedProfileIds)
    • getInjectedProfileIds Link icon

      public Map<String,List<String>> getInjectedProfileIds()
      Gets the identifiers of all profiles that contributed to this project's effective model. This includes active profiles from the project's POM and all its parent POMs as well as from external sources like the settings.xml. The profile identifiers are grouped by the identifier of their source, e.g. <groupId>:<artifactId>:<version> for a POM profile or external for profiles from the settings.xml.
      Returns:
      The identifiers of all injected profiles, indexed by the source from which the profiles originated, never null.
    • addAttachedArtifact Link icon

      public void addAttachedArtifact(Artifact artifact) throws DuplicateArtifactAttachmentException
      Deprecated.
      Add or replace an artifact. This method is now deprecated. Use the @{MavenProjectHelper} to attach artifacts to a project. In spite of the 'throws' declaration on this API, this method has never thrown an exception since Maven 3.0.x. Historically, it logged and ignored a second addition of the same g/a/v/c/t. Now it replaces the file for the artifact, so that plugins (e.g. shade) can change the pathname of the file for a particular set of coordinates.
      Parameters:
      artifact - the artifact to add or replace.
      Throws:
      DuplicateArtifactAttachmentException - will never happen but leave it for backward compatibility
    • getAttachedArtifacts Link icon

      public List<Artifact> getAttachedArtifacts()
      Returns a read-only list of the attached artifacts to this project.
      Returns:
      the attached artifacts of this project
    • getGoalConfiguration Link icon

      public org.codehaus.plexus.util.xml.Xpp3Dom getGoalConfiguration(String pluginGroupId, String pluginArtifactId, String executionId, String goalId)
    • getExecutionProject Link icon

      public MavenProject getExecutionProject()
    • setExecutionProject Link icon

      public void setExecutionProject(MavenProject executionProject)
    • getCollectedProjects Link icon

      public List<MavenProject> getCollectedProjects()
    • setCollectedProjects Link icon

      public void setCollectedProjects(List<MavenProject> collectedProjects)
    • getDependencyArtifacts Link icon

      @Deprecated public Set<Artifact> getDependencyArtifacts()
      Deprecated.
      Direct dependencies that this project has.
      Returns:
      Set < Artifact >
      See Also:
    • setDependencyArtifacts Link icon

      @Deprecated public void setDependencyArtifacts(Set<Artifact> dependencyArtifacts)
      Deprecated.
    • setReleaseArtifactRepository Link icon

      public void setReleaseArtifactRepository(ArtifactRepository releaseArtifactRepository)
    • setSnapshotArtifactRepository Link icon

      public void setSnapshotArtifactRepository(ArtifactRepository snapshotArtifactRepository)
    • setOriginalModel Link icon

      public void setOriginalModel(Model originalModel)
    • getOriginalModel Link icon

      public Model getOriginalModel()
    • setManagedVersionMap Link icon

      public void setManagedVersionMap(Map<String,Artifact> map)
    • getManagedVersionMap Link icon

      public Map<String,Artifact> getManagedVersionMap()
    • equals Link icon

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode Link icon

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getBuildExtensions Link icon

      public List<Extension> getBuildExtensions()
    • addProjectReference Link icon

      public void addProjectReference(MavenProject project)
    • getProperties Link icon

      public Properties getProperties()
    • getFilters Link icon

      public List<String> getFilters()
    • getProjectReferences Link icon

      public Map<String,MavenProject> getProjectReferences()
    • isExecutionRoot Link icon

      public boolean isExecutionRoot()
    • setExecutionRoot Link icon

      public void setExecutionRoot(boolean executionRoot)
    • getDefaultGoal Link icon

      public String getDefaultGoal()
    • getPlugin Link icon

      public Plugin getPlugin(String pluginKey)
    • toString Link icon

      public String toString()
      Default toString
      Overrides:
      toString in class Object
    • clone Link icon

      public MavenProject clone()
      Overrides:
      clone in class Object
      Since:
      2.0.9
    • setModel Link icon

      public void setModel(Model model)
    • setAttachedArtifacts Link icon

      protected void setAttachedArtifacts(List<Artifact> attachedArtifacts)
    • setCompileSourceRoots Link icon

      protected void setCompileSourceRoots(List<String> compileSourceRoots)
    • setTestCompileSourceRoots Link icon

      protected void setTestCompileSourceRoots(List<String> testCompileSourceRoots)
    • getReleaseArtifactRepository Link icon

      protected ArtifactRepository getReleaseArtifactRepository()
    • getSnapshotArtifactRepository Link icon

      protected ArtifactRepository getSnapshotArtifactRepository()
    • setContextValue Link icon

      public void setContextValue(String key, Object value)
      Sets the value of the context value of this project identified by the given key. If the supplied value is null, the context value is removed from this project. Context values are intended to allow core extensions to associate derived state with project instances.
    • getContextValue Link icon

      public Object getContextValue(String key)
      Returns context value of this project associated with the given key or null if this project has no such value.
    • setClassRealm Link icon

      public void setClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm classRealm)
      Sets the project's class realm. Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
      Parameters:
      classRealm - The class realm hosting the build extensions of this project, may be null.
    • getClassRealm Link icon

      public org.codehaus.plexus.classworlds.realm.ClassRealm getClassRealm()
      Gets the project's class realm. This class realm hosts the build extensions of the project. Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
      Returns:
      The project's class realm or null.
    • setExtensionDependencyFilter Link icon

      public void setExtensionDependencyFilter(org.eclipse.aether.graph.DependencyFilter extensionDependencyFilter)
      Sets the artifact filter used to exclude shared extension artifacts from plugin realms. Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
      Parameters:
      extensionDependencyFilter - The dependency filter to apply to plugins, may be null.
    • getExtensionDependencyFilter Link icon

      public org.eclipse.aether.graph.DependencyFilter getExtensionDependencyFilter()
      Gets the dependency filter used to exclude shared extension artifacts from plugin realms. Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
      Returns:
      The dependency filter or null.
    • setResolvedArtifacts Link icon

      public void setResolvedArtifacts(Set<Artifact> artifacts)
      Sets the transitive dependency artifacts that have been resolved/collected for this project. Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
      Parameters:
      artifacts - The set of artifacts, may be null.
    • setArtifactFilter Link icon

      public void setArtifactFilter(ArtifactFilter artifactFilter)
      Sets the scope filter to select the artifacts being exposed to the currently executed mojo. Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
      Parameters:
      artifactFilter - The artifact filter, may be null to exclude all artifacts.
    • hasLifecyclePhase Link icon

      public boolean hasLifecyclePhase(String phase)
      Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
      Parameters:
      phase - The phase to check for, must not be null.
      Returns:
      true if the phase has been seen.
    • addLifecyclePhase Link icon

      public void addLifecyclePhase(String lifecyclePhase)
      Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API. In particular, this method can be changed or deleted without prior notice and must not be used by plugins.
      Parameters:
      lifecyclePhase - The lifecycle phase to add, must not be null.
    • getModulePathAdjustment Link icon

      @Deprecated public String getModulePathAdjustment(MavenProject moduleProject) throws IOException
      Deprecated.
      Throws:
      IOException
    • createArtifacts Link icon

      @Deprecated public Set<Artifact> createArtifacts(ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter filter) throws InvalidDependencyVersionException
      Deprecated.
      Throws:
      InvalidDependencyVersionException
    • setScriptSourceRoots Link icon

      @Deprecated protected void setScriptSourceRoots(List<String> scriptSourceRoots)
      Deprecated.
    • addScriptSourceRoot Link icon

      @Deprecated public void addScriptSourceRoot(String path)
      Deprecated.
    • getScriptSourceRoots Link icon

      @Deprecated public List<String> getScriptSourceRoots()
      Deprecated.
    • getCompileArtifacts Link icon

      @Deprecated public List<Artifact> getCompileArtifacts()
      Deprecated.
    • getCompileDependencies Link icon

      @Deprecated public List<Dependency> getCompileDependencies()
      Deprecated.
    • getTestArtifacts Link icon

      @Deprecated public List<Artifact> getTestArtifacts()
      Deprecated.
    • getTestDependencies Link icon

      @Deprecated public List<Dependency> getTestDependencies()
      Deprecated.
    • getRuntimeDependencies Link icon

      @Deprecated public List<Dependency> getRuntimeDependencies()
      Deprecated.
    • getRuntimeArtifacts Link icon

      @Deprecated public List<Artifact> getRuntimeArtifacts()
      Deprecated.
    • getSystemClasspathElements Link icon

      @Deprecated public List<String> getSystemClasspathElements() throws DependencyResolutionRequiredException
      Deprecated.
      Throws:
      DependencyResolutionRequiredException
    • getSystemArtifacts Link icon

      @Deprecated public List<Artifact> getSystemArtifacts()
      Deprecated.
    • getSystemDependencies Link icon

      @Deprecated public List<Dependency> getSystemDependencies()
      Deprecated.
    • setReporting Link icon

      @Deprecated public void setReporting(Reporting reporting)
      Deprecated.
    • getReporting Link icon

      @Deprecated public Reporting getReporting()
      Deprecated.
    • setReportArtifacts Link icon

      @Deprecated public void setReportArtifacts(Set<Artifact> reportArtifacts)
      Deprecated.
    • getReportArtifacts Link icon

      @Deprecated public Set<Artifact> getReportArtifacts()
      Deprecated.
    • getReportArtifactMap Link icon

      @Deprecated public Map<String,Artifact> getReportArtifactMap()
      Deprecated.
    • setExtensionArtifacts Link icon

      @Deprecated public void setExtensionArtifacts(Set<Artifact> extensionArtifacts)
      Deprecated.
    • getExtensionArtifacts Link icon

      @Deprecated public Set<Artifact> getExtensionArtifacts()
      Deprecated.
    • getExtensionArtifactMap Link icon

      @Deprecated public Map<String,Artifact> getExtensionArtifactMap()
      Deprecated.
    • getReportPlugins Link icon

      @Deprecated public List<ReportPlugin> getReportPlugins()
      Deprecated.
    • getReportConfiguration Link icon

      @Deprecated public org.codehaus.plexus.util.xml.Xpp3Dom getReportConfiguration(String pluginGroupId, String pluginArtifactId, String reportSetId)
      Deprecated.
    • attachArtifact Link icon

      @Deprecated public void attachArtifact(String type, String classifier, File file)
      Deprecated.
      Use MavenProjectHelper.attachArtifact(..) instead.
    • writeModel Link icon

      @Deprecated public void writeModel(Writer writer) throws IOException
      Deprecated.
      Throws:
      IOException
    • writeOriginalModel Link icon

      @Deprecated public void writeOriginalModel(Writer writer) throws IOException
      Deprecated.
      Throws:
      IOException
    • replaceWithActiveArtifact Link icon

      @Deprecated public Artifact replaceWithActiveArtifact(Artifact pluginArtifact)
      Deprecated.
    • getProjectBuildingRequest Link icon

      @Deprecated public ProjectBuildingRequest getProjectBuildingRequest()
      Deprecated.
      Gets the project building request from which this project instance was created. Warning: This is a utility method that is meant to assist integrators of Maven, it must not be used by Maven plugins.
      Returns:
      The project building request or null.
      Since:
      2.1
    • setProjectBuildingRequest Link icon

      @Deprecated public void setProjectBuildingRequest(ProjectBuildingRequest projectBuildingRequest)
      Deprecated.
      Sets the project building request from which this project instance was created. Warning: This is a utility method that is meant to assist integrators of Maven, it must not be used by Maven plugins.
      Parameters:
      projectBuildingRequest - The project building request, may be null.
      Since:
      2.1
    • getRootDirectory Link icon

      public Path getRootDirectory()
      Returns:
      the rootDirectory for this project
      Throws:
      IllegalStateException - if the rootDirectory cannot be found
      Since:
      4.0.0
    • setRootDirectory Link icon

      public void setRootDirectory(Path rootDirectory)