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

  • Constructor Details

    • MavenProject

      public MavenProject()
    • MavenProject

      public MavenProject(Model model)
    • MavenProject

      public MavenProject(MavenProject project)
  • Method Details

    • getParentFile

      public File getParentFile()
    • setParentFile

      public void setParentFile(File parentFile)
    • getArtifact

      public Artifact getArtifact()
    • setArtifact

      public void setArtifact(Artifact artifact)
    • getModel

      public Model getModel()
    • getParent

      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

      public void setParent(MavenProject parent)
    • hasParent

      public boolean hasParent()
    • getFile

      public File getFile()
    • setFile

      public void setFile(File file)
    • setPomFile

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

      public File getBasedir()
    • setDependencies

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

      public List<Dependency> getDependencies()
    • getDependencyManagement

      public DependencyManagement getDependencyManagement()
    • addCompileSourceRoot

      public void addCompileSourceRoot(String path)
    • addTestCompileSourceRoot

      public void addTestCompileSourceRoot(String path)
    • getCompileSourceRoots

      public List<String> getCompileSourceRoots()
    • getTestCompileSourceRoots

      public List<String> getTestCompileSourceRoots()
    • getCompileClasspathElements

      public List<String> getCompileClasspathElements() throws DependencyResolutionRequiredException
      Throws:
      DependencyResolutionRequiredException
    • getTestClasspathElements

      public List<String> getTestClasspathElements() throws DependencyResolutionRequiredException
      Throws:
      DependencyResolutionRequiredException
    • getRuntimeClasspathElements

      public List<String> getRuntimeClasspathElements() throws DependencyResolutionRequiredException
      Throws:
      DependencyResolutionRequiredException
    • setModelVersion

      public void setModelVersion(String pomVersion)
    • getModelVersion

      public String getModelVersion()
    • getId

      public String getId()
    • setGroupId

      public void setGroupId(String groupId)
    • getGroupId

      public String getGroupId()
    • setArtifactId

      public void setArtifactId(String artifactId)
    • getArtifactId

      public String getArtifactId()
    • setName

      public void setName(String name)
    • getName

      public String getName()
    • setVersion

      public void setVersion(String version)
    • getVersion

      public String getVersion()
    • getPackaging

      public String getPackaging()
    • setPackaging

      public void setPackaging(String packaging)
    • setInceptionYear

      public void setInceptionYear(String inceptionYear)
    • getInceptionYear

      public String getInceptionYear()
    • setUrl

      public void setUrl(String url)
    • getUrl

      public String getUrl()
    • getPrerequisites

      public Prerequisites getPrerequisites()
    • setIssueManagement

      public void setIssueManagement(IssueManagement issueManagement)
    • getCiManagement

      public CiManagement getCiManagement()
    • setCiManagement

      public void setCiManagement(CiManagement ciManagement)
    • getIssueManagement

      public IssueManagement getIssueManagement()
    • setDistributionManagement

      public void setDistributionManagement(DistributionManagement distributionManagement)
    • getDistributionManagement

      public DistributionManagement getDistributionManagement()
    • setDescription

      public void setDescription(String description)
    • getDescription

      public String getDescription()
    • setOrganization

      public void setOrganization(Organization organization)
    • getOrganization

      public Organization getOrganization()
    • setScm

      public void setScm(Scm scm)
    • getScm

      public Scm getScm()
    • setMailingLists

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

      public List<MailingList> getMailingLists()
    • addMailingList

      public void addMailingList(MailingList mailingList)
    • setDevelopers

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

      public List<Developer> getDevelopers()
    • addDeveloper

      public void addDeveloper(Developer developer)
    • setContributors

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

      public List<Contributor> getContributors()
    • addContributor

      public void addContributor(Contributor contributor)
    • setBuild

      public void setBuild(Build build)
    • getBuild

      public Build getBuild()
    • getResources

      public List<Resource> getResources()
    • getTestResources

      public List<Resource> getTestResources()
    • addResource

      public void addResource(Resource resource)
    • addTestResource

      public void addTestResource(Resource testResource)
    • setLicenses

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

      public List<License> getLicenses()
    • addLicense

      public void addLicense(License license)
    • setArtifacts

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

      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. eg. if only compile phase has run, dependencies with scope test won't be included.
      Returns:
      Set < Artifact >
      See Also:
    • getArtifactMap

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

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

      public Set<Artifact> getPluginArtifacts()
    • getPluginArtifactMap

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

      public void setParentArtifact(Artifact parentArtifact)
    • getParentArtifact

      public Artifact getParentArtifact()
    • getRepositories

      public List<Repository> getRepositories()
    • getBuildPlugins

      public List<Plugin> getBuildPlugins()
    • getModules

      public List<String> getModules()
    • getPluginManagement

      public PluginManagement getPluginManagement()
    • setRemoteArtifactRepositories

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

      public List<ArtifactRepository> getRemoteArtifactRepositories()
    • setPluginArtifactRepositories

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

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

      public ArtifactRepository getDistributionManagementArtifactRepository()
    • getPluginRepositories

      public List<Repository> getPluginRepositories()
    • getRemoteProjectRepositories

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

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

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

      public List<Profile> getActiveProfiles()
    • setInjectedProfileIds

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

      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

      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

      public List<Artifact> getAttachedArtifacts()
      Returns a mutable list of the attached artifacts to this project. It is highly advised not to modify this list, but rather use the MavenProjectHelper.

      Note: This list will be made read-only in Maven 4.

      Returns:
      the attached artifacts of this project
    • getGoalConfiguration

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

      public MavenProject getExecutionProject()
    • setExecutionProject

      public void setExecutionProject(MavenProject executionProject)
    • getCollectedProjects

      public List<MavenProject> getCollectedProjects()
    • setCollectedProjects

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

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

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

      public void setReleaseArtifactRepository(ArtifactRepository releaseArtifactRepository)
    • setSnapshotArtifactRepository

      public void setSnapshotArtifactRepository(ArtifactRepository snapshotArtifactRepository)
    • setOriginalModel

      public void setOriginalModel(Model originalModel)
    • getOriginalModel

      public Model getOriginalModel()
    • setManagedVersionMap

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

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

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

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

      public List<Extension> getBuildExtensions()
    • addProjectReference

      public void addProjectReference(MavenProject project)
    • getProperties

      public Properties getProperties()
    • getFilters

      public List<String> getFilters()
    • getProjectReferences

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

      public boolean isExecutionRoot()
    • setExecutionRoot

      public void setExecutionRoot(boolean executionRoot)
    • getDefaultGoal

      public String getDefaultGoal()
    • getPlugin

      public Plugin getPlugin(String pluginKey)
    • toString

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

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

      public void setModel(Model model)
    • setAttachedArtifacts

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

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

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

      protected ArtifactRepository getReleaseArtifactRepository()
    • getSnapshotArtifactRepository

      protected ArtifactRepository getSnapshotArtifactRepository()
    • setContextValue

      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

      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

      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

      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

      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

      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

      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

      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

      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

      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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      @Deprecated public Reporting getReporting()
      Deprecated.
    • setReportArtifacts

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

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

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

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

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

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

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

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

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

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

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

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

      @Deprecated public ProjectBuildingRequest getProjectBuildingRequest()
      Deprecated.
      Gets the project building request from which this project instance was created. Warning: This is an 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

      @Deprecated public void setProjectBuildingRequest(ProjectBuildingRequest projectBuildingRequest)
      Deprecated.
      Sets the project building request from which this project instance was created. Warning: This is an 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