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 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.booleanbooleanvoidDeprecated.Replaced byremoveSourceRoot(ProjectScope.MAIN, Language.JAVA_FAMILY, path).voidremoveSourceRoot(ProjectScope scope, Language language, String directory) Removes a source root from the project.voidremoveSourceRoot(ProjectScope scope, Language language, Path directory) Removes a source root from the project.voidDeprecated.Replaced byremoveSourceRoot(ProjectScope.TEST, Language.JAVA_FAMILY, path).replaceWithActiveArtifact(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
-
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
-
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
public void addSourceRoot(@Nonnull ProjectScope scope, @Nonnull Language language, @Nonnull Path directory) 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 newSourceRootelement.- 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
public void addSourceRoot(@Nonnull ProjectScope scope, @Nonnull Language language, @Nonnull String directory) 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 newSourceRootelement 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
-
removeSourceRoot
-
removeSourceRoot
-
addCompileSourceRoot
Deprecated.Replaced byaddSourceRoot(ProjectScope.MAIN, Language.JAVA_FAMILY, path). -
removeCompileSourceRoot
Deprecated.Replaced byremoveSourceRoot(ProjectScope.MAIN, Language.JAVA_FAMILY, path). -
addTestCompileSourceRoot
Deprecated.Replaced byaddSourceRoot(ProjectScope.TEST, Language.JAVA_FAMILY, path). -
removeTestCompileSourceRoot
Deprecated.Replaced byremoveSourceRoot(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, ornullfor all scopeslanguage- the language of the sources to return, ornullfor 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. 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
-
getResources
Deprecated.Replaced bygetEnabledSourceRoots(ProjectScope.MAIN, Language.RESOURCES). -
getTestResources
Deprecated.Replaced bygetEnabledSourceRoots(ProjectScope.TEST, Language.RESOURCES). -
addResource
Deprecated.Resourceis replaced bySourceRoot. -
addTestResource
Deprecated.Resourceis 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 orexternalfor 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 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
-
getAttachedArtifacts
-
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
-
getBuildExtensions
-
addProjectReference
-
getProperties
-
getFilters
-
getProjectReferences
-
isExecutionRoot
public boolean isExecutionRoot() -
setExecutionRoot
public void setExecutionRoot(boolean executionRoot) -
getDefaultGoal
-
getPlugin
-
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
-
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 benullto 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:
trueif 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