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 SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionMavenProject(Model model) MavenProject(Model model) MavenProject(MavenProject project) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddAttachedArtifact(Artifact artifact) Deprecated.voidaddCompileSourceRoot(String path) Deprecated.Replaced byaddSourceRoot(ProjectScope.MAIN, Language.JAVA_FAMILY, path).voidaddContributor(Contributor contributor) voidaddDeveloper(Developer developer) voidaddLicense(License license) voidaddLifecyclePhase(String lifecyclePhase) Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API.voidaddMailingList(MailingList mailingList) voidaddProjectReference(MavenProject project) voidaddResource(Resource resource) Deprecated.Resourceis replaced bySourceRoot.voidaddScriptSourceRoot(String path) Deprecated.voidaddSourceRoot(ProjectScope scope, Language language, String directory) Resolves and adds the given directory as a source with the given scope and language.voidaddSourceRoot(ProjectScope scope, Language language, Path directory) Resolves and adds the given directory as a source with the given scope and language.voidaddSourceRoot(SourceRoot source) Adds the given source if not already present.voidDeprecated.Replaced byaddSourceRoot(ProjectScope.TEST, Language.JAVA_FAMILY, path).voidaddTestResource(Resource testResource) Deprecated.Resourceis replaced bySourceRoot.voidattachArtifact(String type, String classifier, File file) Deprecated.Use MavenProjectHelper.attachArtifact(..) instead.clone()createArtifacts(ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter filter) Deprecated.booleanAll 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.ClassRealmGets 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.DependencyFilterGets the dependency filter used to exclude shared extension artifacts from plugin realms.getFile()org.codehaus.plexus.util.xml.Xpp3DomgetGoalConfiguration(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 ArtifactRepositoryDeprecated.List<org.eclipse.aether.repository.RemoteRepository>List<org.eclipse.aether.repository.RemoteRepository>Deprecated.Deprecated.org.codehaus.plexus.util.xml.Xpp3DomgetReportConfiguration(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 ArtifactRepositoryReturns 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()inthashCode()booleanhasLifecyclePhase(String phase) Warning: This is an internal utility method that is only public for technical reasons, it is not part of the public API.booleanbooleanreplaceWithActiveArtifact(Artifact pluginArtifact) Deprecated.voidsetActiveProfiles(List<Profile> activeProfiles) voidsetArtifact(Artifact artifact) voidsetArtifactFilter(ArtifactFilter artifactFilter) Sets the scope filter to select the artifacts being exposed to the currently executed mojo.voidsetArtifactId(String artifactId) voidsetArtifacts(Set<Artifact> artifacts) protected voidsetAttachedArtifacts(List<Artifact> attachedArtifacts) voidvoidsetCiManagement(CiManagement ciManagement) voidsetClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm classRealm) Sets the project's class realm.voidsetCollectedProjects(List<MavenProject> collectedProjects) protected voidsetCompileSourceRoots(List<String> compileSourceRoots) Deprecated.Replaced byaddSourceRoot(ProjectScope, Language, String).voidsetContextValue(String key, Object value) Sets the value of the context value of this project identified by the given key.voidsetContributors(List<Contributor> contributors) voidsetDependencies(List<Dependency> dependencies) voidsetDependencyArtifacts(Set<Artifact> dependencyArtifacts) Deprecated.voidsetDescription(String description) voidsetDevelopers(List<Developer> developers) voidsetDistributionManagement(DistributionManagement distributionManagement) voidsetExecutionProject(MavenProject executionProject) voidsetExecutionRoot(boolean executionRoot) voidsetExtensionArtifacts(Set<Artifact> extensionArtifacts) Deprecated.voidsetExtensionDependencyFilter(org.eclipse.aether.graph.DependencyFilter extensionDependencyFilter) Sets the artifact filter used to exclude shared extension artifacts from plugin realms.voidvoidsetGroupId(String groupId) voidsetInceptionYear(String inceptionYear) voidsetInjectedProfileIds(String source, List<String> injectedProfileIds) voidsetIssueManagement(IssueManagement issueManagement) voidsetLicenses(List<License> licenses) voidsetMailingLists(List<MailingList> mailingLists) voidvoidvoidsetModelVersion(String pomVersion) voidvoidsetOrganization(Organization organization) voidsetOriginalModel(Model originalModel) voidsetPackaging(String packaging) voidsetParent(MavenProject parent) voidsetParentArtifact(Artifact parentArtifact) voidsetParentFile(File parentFile) voidsetPluginArtifactRepositories(List<ArtifactRepository> pluginArtifactRepositories) Deprecated.voidsetPluginArtifacts(Set<Artifact> pluginArtifacts) voidsetPomFile(File file) Sets projectfilewithout changing projectbasedir.voidsetProjectBuildingRequest(ProjectBuildingRequest projectBuildingRequest) Deprecated.voidsetReleaseArtifactRepository(ArtifactRepository releaseArtifactRepository) Deprecated.voidsetRemoteArtifactRepositories(List<ArtifactRepository> remoteArtifactRepositories) Deprecated.voidsetReportArtifacts(Set<Artifact> reportArtifacts) Deprecated.voidsetReporting(Reporting reporting) Deprecated.voidsetResolvedArtifacts(Set<Artifact> artifacts) Sets the transitive dependency artifacts that have been resolved/collected for this project.voidsetRootDirectory(Path rootDirectory) voidprotected voidsetScriptSourceRoots(List<String> scriptSourceRoots) Deprecated.voidsetSnapshotArtifactRepository(ArtifactRepository snapshotArtifactRepository) Deprecated.protected voidsetTestCompileSourceRoots(List<String> testCompileSourceRoots) Deprecated.Replaced byaddSourceRoot(ProjectScope, Language, String).voidvoidsetVersion(String version) toString()Default toStringvoidwriteModel(Writer writer) Deprecated.UseModelWriter.voidwriteOriginalModel(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- 
MavenProjectpublic MavenProject()
- 
MavenProject
- 
MavenProject
- 
MavenProject
 
- 
- 
Method Details- 
getParentFile
- 
setParentFile
- 
getArtifact
- 
setArtifact
- 
getModel
- 
getParentReturns 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
- 
hasParentpublic boolean hasParent()
- 
getFile
- 
setFile
- 
setPomFileSets projectfilewithout changing projectbasedir.- Since:
- 3.2.4
 
- 
getBasedirDeprecated.
- 
getBaseDirectoryReturns 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
- 
addSourceRootAdds the given source if not already present.- Parameters:
- source- the source to add
- Since:
- 4.0.0
- See Also:
 
- 
addSourceRootResolves 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 newSourceRootelement.- Parameters:
- scope- scope (main or test) of the directory to add
- language- language of the files contained in the directory to add
- directory- the directory to add if not already present in the source
- Since:
- 4.0.0
- See Also:
 
- 
addSourceRootResolves 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 newSourceRootelement if no source exists for these scope, language and normalized directory.- Parameters:
- scope- scope (main or test) of the directory to add
- language- language of the files contained in the directory to add
- directory- the directory to add if not already present in the source, or null
- Since:
- 4.0.0
 
- 
addCompileSourceRootDeprecated.Replaced byaddSourceRoot(ProjectScope.MAIN, Language.JAVA_FAMILY, path).
- 
addTestCompileSourceRootDeprecated.Replaced byaddSourceRoot(ProjectScope.TEST, Language.JAVA_FAMILY, path).
- 
getSourceRootsReturns 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:
 
- 
getEnabledSourceRootsReturns 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, or- nullfor all scopes
- language- the language of the sources to return, or- nullfor all languages
- Returns:
- all enabled sources that provide files in the given language for the given scope
- Since:
- 4.0.0
- See Also:
 
- 
getCompileSourceRootsDeprecated.Replaced bygetEnabledSourceRoots(ProjectScope.MAIN, Language.JAVA_FAMILY).
- 
getTestCompileSourceRootsDeprecated.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. SeeJavaPathTypeinstead 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. SeeJavaPathTypeinstead 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. SeeJavaPathTypeinstead 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
- 
getResourcesDeprecated.Replaced bygetEnabledSourceRoots(ProjectScope.MAIN, Language.RESOURCES).
- 
getTestResourcesDeprecated.Replaced bygetEnabledSourceRoots(ProjectScope.TEST, Language.RESOURCES).
- 
addResourceDeprecated.Resourceis replaced bySourceRoot.
- 
addTestResourceDeprecated.Resourceis replaced bySourceRoot.
- 
setLicenses
- 
getLicenses
- 
addLicense
- 
setArtifacts
- 
getArtifactsAll 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.
- 
getRemoteArtifactRepositoriesDeprecated.
- 
setPluginArtifactRepositories@Deprecated public void setPluginArtifactRepositories(List<ArtifactRepository> pluginArtifactRepositories) Deprecated.
- 
getPluginArtifactRepositoriesDeprecated.- Returns:
- a list of ArtifactRepository objects constructed from the Repository objects returned by getPluginRepositories.
 
- 
getDistributionManagementArtifactRepositoryDeprecated.
- 
getPluginRepositories
- 
getRemoteProjectRepositories
- 
getRemotePluginRepositories
- 
setActiveProfiles
- 
getActiveProfiles
- 
setInjectedProfileIds
- 
getInjectedProfileIdsGets 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 orexternalfor profiles from thesettings.xml.- Returns:
- The identifiers of all injected profiles, indexed by the source from which the profiles originated, never
         null.
 
- 
addAttachedArtifactDeprecated.Please useMavenProjectHelperAdd 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
 
- 
getAttachedArtifactsReturns a read-only list of the attached artifacts to this project.- Returns:
- the attached artifacts of this project
 
- 
getGoalConfiguration
- 
getExecutionProject
- 
setExecutionProject
- 
getCollectedProjects
- 
setCollectedProjects
- 
getDependencyArtifactsDeprecated.Direct dependencies that this project has.
- 
setDependencyArtifactsDeprecated.
- 
setReleaseArtifactRepositoryDeprecated.
- 
setSnapshotArtifactRepository@Deprecated public void setSnapshotArtifactRepository(ArtifactRepository snapshotArtifactRepository) Deprecated.
- 
setOriginalModel
- 
getOriginalModel
- 
setManagedVersionMap
- 
getManagedVersionMap
- 
equals
- 
hashCodepublic int hashCode()
- 
getBuildExtensions
- 
addProjectReference
- 
getProperties
- 
getFilters
- 
getProjectReferences
- 
isExecutionRootpublic boolean isExecutionRoot()
- 
setExecutionRootpublic void setExecutionRoot(boolean executionRoot) 
- 
getDefaultGoal
- 
getPlugin
- 
toStringDefault toString
- 
clone
- 
setModel
- 
setAttachedArtifacts
- 
setCompileSourceRootsDeprecated.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
- 
setContextValueSets 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.
- 
getContextValueReturns context value of this project associated with the given key or null if this project has no such value.
- 
setClassRealmpublic 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.
 
- 
getClassRealmpublic 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.
 
- 
setExtensionDependencyFilterpublic 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.
 
- 
getExtensionDependencyFilterpublic 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.
 
- 
setResolvedArtifactsSets 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.
 
- 
setArtifactFilterSets 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- nullto exclude all artifacts.
 
- 
hasLifecyclePhaseWarning: 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:
- trueif the phase has been seen.
 
- 
addLifecyclePhaseWarning: 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.
 
- 
getModulePathAdjustmentDeprecated.- Throws:
- IOException
 
- 
createArtifacts@Deprecated public Set<Artifact> createArtifacts(ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter filter) throws InvalidDependencyVersionException Deprecated.
- 
setScriptSourceRootsDeprecated.
- 
addScriptSourceRootDeprecated.
- 
getScriptSourceRootsDeprecated.
- 
getCompileArtifactsDeprecated.
- 
getCompileDependenciesDeprecated.
- 
getTestArtifactsDeprecated.
- 
getTestDependenciesDeprecated.
- 
getRuntimeDependenciesDeprecated.
- 
getRuntimeArtifactsDeprecated.
- 
getSystemClasspathElements@Deprecated public List<String> getSystemClasspathElements() throws DependencyResolutionRequiredExceptionDeprecated.
- 
getSystemArtifactsDeprecated.
- 
getSystemDependenciesDeprecated.
- 
setReportingDeprecated.
- 
getReportingDeprecated.
- 
setReportArtifactsDeprecated.
- 
getReportArtifactsDeprecated.
- 
getReportArtifactMapDeprecated.
- 
setExtensionArtifactsDeprecated.
- 
getExtensionArtifactsDeprecated.
- 
getExtensionArtifactMapDeprecated.
- 
getReportPluginsDeprecated.
- 
getReportConfiguration@Deprecated public org.codehaus.plexus.util.xml.Xpp3Dom getReportConfiguration(String pluginGroupId, String pluginArtifactId, String reportSetId) Deprecated.
- 
attachArtifactDeprecated.Use MavenProjectHelper.attachArtifact(..) instead.
- 
writeModelDeprecated.UseModelWriter.- Throws:
- IOException
 
- 
writeOriginalModelDeprecated.UseModelWriter.- Throws:
- IOException
 
- 
replaceWithActiveArtifactDeprecated.
- 
getProjectBuildingRequestDeprecated.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
 
- 
setProjectBuildingRequestDeprecated.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- Returns:
- the rootDirectory for this project
- Throws:
- IllegalStateException- if the rootDirectory cannot be found
- Since:
- 4.0.0
 
- 
setRootDirectory
 
- 
MavenProjectHelper