Class MavenProject
- All Implemented Interfaces:
Cloneable
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMavenProject
(Model model) MavenProject
(Model model) MavenProject
(MavenProject project) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttachedArtifact
(Artifact artifact) Deprecated.void
addCompileSourceRoot
(String path) Deprecated.Replaced byaddSourceRoot(ProjectScope.MAIN, Language.JAVA_FAMILY, path)
.void
addContributor
(Contributor contributor) void
addDeveloper
(Developer developer) void
addLicense
(License license) 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.void
addMailingList
(MailingList mailingList) void
addProjectReference
(MavenProject project) void
addResource
(Resource resource) Deprecated.Resource
is replaced bySourceRoot
.void
addScriptSourceRoot
(String path) Deprecated.void
addSourceRoot
(ProjectScope scope, Language language, String directory) Resolves and adds the given directory as a source with the given scope and language.void
addSourceRoot
(ProjectScope scope, Language language, Path directory) Resolves and adds the given directory as a source with the given scope and language.void
addSourceRoot
(SourceRoot source) Adds the given source if not already present.void
Deprecated.Replaced byaddSourceRoot(ProjectScope.TEST, Language.JAVA_FAMILY, path)
.void
addTestResource
(Resource testResource) Deprecated.Resource
is replaced bySourceRoot
.void
attachArtifact
(String type, String classifier, File file) Deprecated.Use MavenProjectHelper.attachArtifact(..) instead.clone()
createArtifacts
(ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter filter) Deprecated.boolean
All dependencies that this project has, including transitive ones.Returns a read-only list of the attached artifacts to this project.Deprecated.Returns the base directory of this project.getBuild()
org.codehaus.plexus.classworlds.realm.ClassRealm
Gets the project's class realm.Deprecated.Deprecated.This method is unreliable because it does not consider other dependency properties.Deprecated.Deprecated.Replaced bygetEnabledSourceRoots(ProjectScope.MAIN, Language.JAVA_FAMILY)
.getContextValue
(String key) Returns context value of this project associated with the given key or null if this project has no such value.Deprecated.Deprecated.getEnabledSourceRoots
(ProjectScope scope, Language language) Returns all enabled sources that provide files in the given language for the given scope.Deprecated.Deprecated.org.eclipse.aether.graph.DependencyFilter
Gets the dependency filter used to exclude shared extension artifacts from plugin realms.getFile()
org.codehaus.plexus.util.xml.Xpp3Dom
getGoalConfiguration
(String pluginGroupId, String pluginArtifactId, String executionId, String goalId) getId()
Gets the identifiers of all profiles that contributed to this project's effective model.getModel()
getModulePathAdjustment
(MavenProject moduleProject) Deprecated.getName()
Returns the project corresponding to a declared parent.Deprecated.Deprecated.protected ArtifactRepository
Deprecated.List<org.eclipse.aether.repository.RemoteRepository>
List<org.eclipse.aether.repository.RemoteRepository>
Deprecated.Deprecated.org.codehaus.plexus.util.xml.Xpp3Dom
getReportConfiguration
(String pluginGroupId, String pluginArtifactId, String reportSetId) Deprecated.Deprecated.Deprecated.Deprecated.Replaced bygetEnabledSourceRoots(ProjectScope.MAIN, Language.RESOURCES)
.Deprecated.Deprecated.This method is unreliable because it does not consider other dependency properties.Deprecated.getScm()
Deprecated.protected ArtifactRepository
Returns all source root directories, including the disabled ones, for all languages and scopes.Deprecated.Deprecated.Deprecated.Deprecated.Deprecated.This method is unreliable because it does not consider other dependency properties.Deprecated.Replaced bygetEnabledSourceRoots(ProjectScope.TEST, Language.JAVA_FAMILY)
.Deprecated.Deprecated.Replaced bygetEnabledSourceRoots(ProjectScope.TEST, Language.RESOURCES)
.getUrl()
int
hashCode()
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.boolean
boolean
replaceWithActiveArtifact
(Artifact pluginArtifact) Deprecated.void
setActiveProfiles
(List<Profile> activeProfiles) void
setArtifact
(Artifact artifact) void
setArtifactFilter
(ArtifactFilter artifactFilter) Sets the scope filter to select the artifacts being exposed to the currently executed mojo.void
setArtifactId
(String artifactId) void
setArtifacts
(Set<Artifact> artifacts) protected void
setAttachedArtifacts
(List<Artifact> attachedArtifacts) void
void
setCiManagement
(CiManagement ciManagement) void
setClassRealm
(org.codehaus.plexus.classworlds.realm.ClassRealm classRealm) Sets the project's class realm.void
setCollectedProjects
(List<MavenProject> collectedProjects) protected void
setCompileSourceRoots
(List<String> compileSourceRoots) Deprecated.Replaced byaddSourceRoot(ProjectScope, Language, String)
.void
setContextValue
(String key, Object value) Sets the value of the context value of this project identified by the given key.void
setContributors
(List<Contributor> contributors) void
setDependencies
(List<Dependency> dependencies) void
setDependencyArtifacts
(Set<Artifact> dependencyArtifacts) Deprecated.void
setDescription
(String description) void
setDevelopers
(List<Developer> developers) void
setDistributionManagement
(DistributionManagement distributionManagement) void
setExecutionProject
(MavenProject executionProject) void
setExecutionRoot
(boolean executionRoot) void
setExtensionArtifacts
(Set<Artifact> extensionArtifacts) Deprecated.void
setExtensionDependencyFilter
(org.eclipse.aether.graph.DependencyFilter extensionDependencyFilter) Sets the artifact filter used to exclude shared extension artifacts from plugin realms.void
void
setGroupId
(String groupId) void
setInceptionYear
(String inceptionYear) void
setInjectedProfileIds
(String source, List<String> injectedProfileIds) void
setIssueManagement
(IssueManagement issueManagement) void
setLicenses
(List<License> licenses) void
setMailingLists
(List<MailingList> mailingLists) void
void
void
setModelVersion
(String pomVersion) void
void
setOrganization
(Organization organization) void
setOriginalModel
(Model originalModel) void
setPackaging
(String packaging) void
setParent
(MavenProject parent) void
setParentArtifact
(Artifact parentArtifact) void
setParentFile
(File parentFile) void
setPluginArtifactRepositories
(List<ArtifactRepository> pluginArtifactRepositories) Deprecated.void
setPluginArtifacts
(Set<Artifact> pluginArtifacts) void
setPomFile
(File file) Sets projectfile
without changing projectbasedir
.void
setProjectBuildingRequest
(ProjectBuildingRequest projectBuildingRequest) Deprecated.void
setReleaseArtifactRepository
(ArtifactRepository releaseArtifactRepository) Deprecated.void
setRemoteArtifactRepositories
(List<ArtifactRepository> remoteArtifactRepositories) Deprecated.void
setReportArtifacts
(Set<Artifact> reportArtifacts) Deprecated.void
setReporting
(Reporting reporting) Deprecated.void
setResolvedArtifacts
(Set<Artifact> artifacts) Sets the transitive dependency artifacts that have been resolved/collected for this project.void
setRootDirectory
(Path rootDirectory) void
protected void
setScriptSourceRoots
(List<String> scriptSourceRoots) Deprecated.void
setSnapshotArtifactRepository
(ArtifactRepository snapshotArtifactRepository) Deprecated.protected void
setTestCompileSourceRoots
(List<String> testCompileSourceRoots) Deprecated.Replaced byaddSourceRoot(ProjectScope, Language, String)
.void
void
setVersion
(String version) toString()
Default toStringvoid
writeModel
(Writer writer) Deprecated.UseModelWriter
.void
writeOriginalModel
(Writer writer) Deprecated.UseModelWriter
.
-
Field Details
-
EMPTY_PROJECT_GROUP_ID
- See Also:
-
EMPTY_PROJECT_ARTIFACT_ID
- See Also:
-
EMPTY_PROJECT_VERSION
- See Also:
-
-
Constructor Details
-
MavenProject
public MavenProject() -
MavenProject
-
MavenProject
-
MavenProject
-
-
Method Details
-
getParentFile
-
setParentFile
-
getArtifact
-
setArtifact
-
getModel
-
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
-
hasParent
public boolean hasParent() -
getFile
-
setFile
-
setPomFile
Sets projectfile
without changing projectbasedir
.- Since:
- 3.2.4
-
getBasedir
Deprecated. -
getBaseDirectory
Returns the base directory of this project.. All source files are relative to this directory, unless they were specified as absolute paths.- Returns:
- the base directory of this project
- Since:
- 4.0.0
-
setDependencies
-
getDependencies
-
getDependencyManagement
-
addSourceRoot
Adds the given source if not already present.- Parameters:
source
- the source to add- Since:
- 4.0.0
- See Also:
-
addSourceRoot
Resolves and adds the given directory as a source with the given scope and language. First, this method resolves the given root against the base directory, then normalizes the path. If a source already exists for the same scope, language and normalized directory, this method does nothing. Otherwise, the normalized directory is added as a newSourceRoot
element.- Parameters:
scope
- scope (main or test) of the directory to addlanguage
- language of the files contained in the directory to adddirectory
- the directory to add if not already present in the source- Since:
- 4.0.0
- See Also:
-
addSourceRoot
Resolves and adds the given directory as a source with the given scope and language. If the given directory is null, blank or already in the sources, then this method does nothing. Otherwise, the directory is converted to a path, resolved, normalized and finally added as a newSourceRoot
element if no source exists for these scope, language and normalized directory.- Parameters:
scope
- scope (main or test) of the directory to addlanguage
- language of the files contained in the directory to adddirectory
- the directory to add if not already present in the source, or null- Since:
- 4.0.0
-
addCompileSourceRoot
Deprecated.Replaced byaddSourceRoot(ProjectScope.MAIN, Language.JAVA_FAMILY, path)
. -
addTestCompileSourceRoot
Deprecated.Replaced byaddSourceRoot(ProjectScope.TEST, Language.JAVA_FAMILY, path)
. -
getSourceRoots
Returns all source root directories, including the disabled ones, for all languages and scopes.. The iteration order is the order in which the sources are declared in the POM file. The returned collection is unmodifiable.- Returns:
- all source root directories, including the disabled ones, for all languages and scopes
- See Also:
-
getEnabledSourceRoots
Returns all enabled sources that provide files in the given language for the given scope.. If the given scope isnull
, then this method returns the enabled sources for all scopes. If the given language isnull
, then this method returns the enabled sources for all languages. The iteration order is the order in which the sources are declared in the POM file.- Parameters:
scope
- the scope of the sources to return, ornull
for all scopeslanguage
- the language of the sources to return, ornull
for all languages- Returns:
- all enabled sources that provide files in the given language for the given scope
- Since:
- 4.0.0
- See Also:
-
getCompileSourceRoots
Deprecated.Replaced bygetEnabledSourceRoots(ProjectScope.MAIN, Language.JAVA_FAMILY)
. -
getTestCompileSourceRoots
Deprecated.Replaced bygetEnabledSourceRoots(ProjectScope.TEST, Language.JAVA_FAMILY)
. -
getCompileClasspathElements
@Deprecated public List<String> getCompileClasspathElements() throws DependencyResolutionRequiredExceptionDeprecated.This method is unreliable because it does not consider other dependency properties. SeeJavaPathType
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
@Deprecated public List<String> getTestClasspathElements() throws DependencyResolutionRequiredExceptionDeprecated.This method is unreliable because it does not consider other dependency properties. SeeJavaPathType
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
@Deprecated public List<String> getRuntimeClasspathElements() throws DependencyResolutionRequiredExceptionDeprecated.This method is unreliable because it does not consider other dependency properties. SeeJavaPathType
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
-
getModelVersion
-
getId
-
setGroupId
-
getGroupId
-
setArtifactId
-
getArtifactId
-
setName
-
getName
-
setVersion
-
getVersion
-
getPackaging
-
setPackaging
-
setInceptionYear
-
getInceptionYear
-
setUrl
-
getUrl
-
getPrerequisites
-
setIssueManagement
-
getCiManagement
-
setCiManagement
-
getIssueManagement
-
setDistributionManagement
-
getDistributionManagement
-
setDescription
-
getDescription
-
setOrganization
-
getOrganization
-
setScm
-
getScm
-
setMailingLists
-
getMailingLists
-
addMailingList
-
setDevelopers
-
getDevelopers
-
addDeveloper
-
setContributors
-
getContributors
-
addContributor
-
setBuild
-
getBuild
-
getResources
Deprecated.Replaced bygetEnabledSourceRoots(ProjectScope.MAIN, Language.RESOURCES)
. -
getTestResources
Deprecated.Replaced bygetEnabledSourceRoots(ProjectScope.TEST, Language.RESOURCES)
. -
addResource
Deprecated.Resource
is replaced bySourceRoot
. -
addTestResource
Deprecated.Resource
is replaced bySourceRoot
. -
setLicenses
-
getLicenses
-
addLicense
-
setArtifacts
-
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. -
getArtifactMap
-
setPluginArtifacts
-
getPluginArtifacts
-
getPluginArtifactMap
-
setParentArtifact
-
getParentArtifact
-
getRepositories
-
getBuildPlugins
-
getModules
-
getPluginManagement
-
setRemoteArtifactRepositories
@Deprecated public void setRemoteArtifactRepositories(List<ArtifactRepository> remoteArtifactRepositories) Deprecated. -
getRemoteArtifactRepositories
Deprecated. -
setPluginArtifactRepositories
@Deprecated public void setPluginArtifactRepositories(List<ArtifactRepository> pluginArtifactRepositories) Deprecated. -
getPluginArtifactRepositories
Deprecated.- Returns:
- a list of ArtifactRepository objects constructed from the Repository objects returned by getPluginRepositories.
-
getDistributionManagementArtifactRepository
Deprecated. -
getPluginRepositories
-
getRemoteProjectRepositories
-
getRemotePluginRepositories
-
setActiveProfiles
-
getActiveProfiles
-
setInjectedProfileIds
-
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 thesettings.xml
. The profile identifiers are grouped by the identifier of their source, e.g.<groupId>:<artifactId>:<version>
for a POM profile orexternal
for profiles from thesettings.xml
.- Returns:
- The identifiers of all injected profiles, indexed by the source from which the profiles originated, never
null
.
-
addAttachedArtifact
Deprecated.Please useMavenProjectHelper
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
Returns a read-only list of the attached artifacts to this project.- Returns:
- the attached artifacts of this project
-
getGoalConfiguration
-
getExecutionProject
-
setExecutionProject
-
getCollectedProjects
-
setCollectedProjects
-
getDependencyArtifacts
Deprecated.Direct dependencies that this project has. -
setDependencyArtifacts
Deprecated. -
setReleaseArtifactRepository
Deprecated. -
setSnapshotArtifactRepository
@Deprecated public void setSnapshotArtifactRepository(ArtifactRepository snapshotArtifactRepository) Deprecated. -
setOriginalModel
-
getOriginalModel
-
setManagedVersionMap
-
getManagedVersionMap
-
equals
-
hashCode
public int hashCode() -
getBuildExtensions
-
addProjectReference
-
getProperties
-
getFilters
-
getProjectReferences
-
isExecutionRoot
public boolean isExecutionRoot() -
setExecutionRoot
public void setExecutionRoot(boolean executionRoot) -
getDefaultGoal
-
getPlugin
-
toString
Default toString -
clone
-
setModel
-
setAttachedArtifacts
-
setCompileSourceRoots
Deprecated.Replaced byaddSourceRoot(ProjectScope, Language, String)
. -
setTestCompileSourceRoots
@Deprecated(since="4.0.0") protected void setTestCompileSourceRoots(List<String> testCompileSourceRoots) Deprecated.Replaced byaddSourceRoot(ProjectScope, Language, String)
. -
getReleaseArtifactRepository
-
getSnapshotArtifactRepository
-
setContextValue
Sets the value of the context value of this project identified by the given key. If the supplied value isnull
, the context value is removed from this project. Context values are intended to allow core extensions to associate derived state with project instances. -
getContextValue
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 benull
.
-
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 benull
.
-
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
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 benull
.
-
setArtifactFilter
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 benull
to exclude all artifacts.
-
hasLifecyclePhase
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 benull
.- Returns:
true
if the phase has been seen.
-
addLifecyclePhase
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 benull
.
-
getModulePathAdjustment
Deprecated.- Throws:
IOException
-
createArtifacts
@Deprecated public Set<Artifact> createArtifacts(ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter filter) throws InvalidDependencyVersionException Deprecated. -
setScriptSourceRoots
Deprecated. -
addScriptSourceRoot
Deprecated. -
getScriptSourceRoots
Deprecated. -
getCompileArtifacts
Deprecated. -
getCompileDependencies
Deprecated. -
getTestArtifacts
Deprecated. -
getTestDependencies
Deprecated. -
getRuntimeDependencies
Deprecated. -
getRuntimeArtifacts
Deprecated. -
getSystemClasspathElements
@Deprecated public List<String> getSystemClasspathElements() throws DependencyResolutionRequiredExceptionDeprecated. -
getSystemArtifacts
Deprecated. -
getSystemDependencies
Deprecated. -
setReporting
Deprecated. -
getReporting
Deprecated. -
setReportArtifacts
Deprecated. -
getReportArtifacts
Deprecated. -
getReportArtifactMap
Deprecated. -
setExtensionArtifacts
Deprecated. -
getExtensionArtifacts
Deprecated. -
getExtensionArtifactMap
Deprecated. -
getReportPlugins
Deprecated. -
getReportConfiguration
@Deprecated public org.codehaus.plexus.util.xml.Xpp3Dom getReportConfiguration(String pluginGroupId, String pluginArtifactId, String reportSetId) Deprecated. -
attachArtifact
Deprecated.Use MavenProjectHelper.attachArtifact(..) instead. -
writeModel
Deprecated.UseModelWriter
.- Throws:
IOException
-
writeOriginalModel
Deprecated.UseModelWriter
.- Throws:
IOException
-
replaceWithActiveArtifact
Deprecated. -
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
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 benull
.- Since:
- 2.1
-
getRootDirectory
- Returns:
- the rootDirectory for this project
- Throws:
IllegalStateException
- if the rootDirectory cannot be found- Since:
- 4.0.0
-
setRootDirectory
-
MavenProjectHelper