Interface Project

All Known Implementing Classes:
DefaultProject

@Experimental public interface Project
Interface representing a Maven project which can be created using the ProjectBuilder service. Such objects are immutable and plugin that wish to modify such objects need to do so using the ProjectManager service.

Projects are created using the ProjectBuilder from a POM file (usually named pom.xml) on the file system. The getPomPath() will point to the POM file and the getBasedir() to the directory parent containing the POM file.

Since:
4.0.0
See Also:
  • Method Details

    • getGroupId

      @Nonnull String getGroupId()
      Returns the project groupId..
      Returns:
      the project groupId
    • getArtifactId

      @Nonnull String getArtifactId()
      Returns the project artifactId..
      Returns:
      the project artifactId
    • getVersion

      @Nonnull String getVersion()
      Returns the project version..
      Returns:
      the project version
    • getPackaging

      @Nonnull Packaging getPackaging()
      Returns the project packaging..

      Note: unlike in legacy code, logical checks against string representing packaging (returned by this method) are NOT recommended (code like "pom".equals(project.getPackaging) must be avoided). Use method getArtifacts() to gain access to POM or build artifact.

      Returns:
      the project packaging
      See Also:
    • getLanguage

      @Nonnull default Language getLanguage()
      Returns the project language.. It is by default determined by getPackaging().
      Returns:
      the project language
      See Also:
    • getPomArtifact

      @Nonnull default ProducedArtifact getPomArtifact()
      Returns the project POM artifact., which is the artifact of the POM of this project. Every project have a POM artifact, even if the existence of backing POM file is NOT a requirement (i.e. for some transient projects).
      Returns:
      the project POM artifact
      See Also:
    • getMainArtifact

      @Nonnull default Optional<ProducedArtifact> getMainArtifact()
      Returns the project main artifact., which is the artifact produced by this project build, if applicable. This artifact MAY be absent if the project is actually not producing any main artifact (i.e. "pom" packaging).
      Returns:
      the project main artifact
      See Also:
    • getArtifacts

      @Nonnull List<ProducedArtifact> getArtifacts()
      Returns the project artifacts as immutable list.. Elements are the project POM artifact and the artifact produced by this project build, if applicable. Hence, the returned list may have one or two elements (never less than 1, never more than 2), depending on project packaging.

      The list's first element is ALWAYS the project POM artifact. Presence of second element in the list depends solely on the project packaging.

      Returns:
      the project artifacts as immutable list
      See Also:
    • getModel

      @Nonnull Model getModel()
      Returns the project model..
      Returns:
      the project model
    • getBuild

      @Nonnull default Build getBuild()
      Shorthand method.
      Returns:
      the build element of the project model
    • getPomPath

      @Nonnull Path getPomPath()
      Returns the path to the pom file for this project. A project is usually read from a file named pom.xml, which contains the model in an XML form. When a custom org.apache.maven.api.spi.ModelParser is used, the path may point to a non XML file.

      The POM path is also used to define the base directory of the project.

      Returns:
      the path of the pom
      See Also:
    • getBasedir

      @Nonnull Path getBasedir()
      Returns the project base directory, i.e. the directory containing the project. A project is usually read from the file system and this will point to the directory containing the POM file.
      Returns:
      the path of the directory containing the project
    • getDependencies

      @Nonnull List<DependencyCoordinates> getDependencies()
      Returns the project direct dependencies (directly specified or inherited)..
      Returns:
      the project direct dependencies (directly specified or inherited)
    • getManagedDependencies

      @Nonnull List<DependencyCoordinates> getManagedDependencies()
      Returns the project managed dependencies (directly specified or inherited)..
      Returns:
      the project managed dependencies (directly specified or inherited)
    • getId

      @Nonnull default String getId()
      Returns the project ID, usable as key..
      Returns:
      the project ID, usable as key
    • isTopProject

      boolean isTopProject()
      Returns a boolean indicating if the project is the top level project for this reactor build. The top level project may be different from the rootDirectory, especially if a subtree of the project is being built, either because Maven has been launched in a subdirectory or using a -f option.
      Returns:
      true if the project is the top level project for this build
    • isRootProject

      boolean isRootProject()
      Returns a boolean indicating if the project is a root project, meaning that the getRootDirectory() and getBasedir() points to the same directory, and that either Model.isRoot() is true or that basedir contains a .mvn child directory.
      Returns:
      true if the project is the root project
      See Also:
    • getRootDirectory

      @Nonnull Path getRootDirectory()
      Gets the root directory of the project, which is the parent directory containing the .mvn directory or flagged with root="true".
      Returns:
      the root directory of the project
      Throws:
      IllegalStateException - if the root directory could not be found
      See Also:
    • getParent

      @Nonnull Optional<Project> getParent()
      Returns project parent project, if any.

      Note that the model may have a parent defined, but an empty parent project may be returned if the parent comes from a remote repository, as a Project must refer to a buildable project.

      Returns:
      an optional containing the parent project
      See Also:
    • getDeclaredProfiles

      @Nonnull List<Profile> getDeclaredProfiles()
      Returns all profiles defined in this project.

      This method returns only the profiles defined directly in the current project's POM and does not include profiles from parent projects.

      Returns:
      a non-null, possibly empty list of profiles defined in this project
      See Also:
    • getEffectiveProfiles

      @Nonnull List<Profile> getEffectiveProfiles()
      Returns all profiles defined in this project and all of its parent projects.

      This method traverses the parent hierarchy and includes profiles defined in parent POMs. The returned list contains profiles from the current project and all of its ancestors in the project inheritance chain.

      Returns:
      a non-null, possibly empty list of all profiles from this project and its parents
      See Also:
    • getDeclaredActiveProfiles

      @Nonnull List<Profile> getDeclaredActiveProfiles()
      Returns all active profiles for the current project build.

      Active profiles are those that have been explicitly activated through one of the following means:

      • Command line activation using the -P flag
      • Maven settings activation in settings.xml via <activeProfiles>
      • Automatic activation via <activation> conditions
      • The default active profile (marked with <activeByDefault>true</activeByDefault>)

      The active profiles control various aspects of the build configuration including but not limited to dependencies, plugins, properties, and build resources.

      Returns:
      a non-null, possibly empty list of active profiles for this project
      See Also:
    • getEffectiveActiveProfiles

      @Nonnull List<Profile> getEffectiveActiveProfiles()
      Returns all active profiles for this project and all of its parent projects.

      This method traverses the parent hierarchy and collects all active profiles from the current project and its ancestors. Active profiles are those that meet the activation criteria through explicit activation or automatic conditions.

      The combined set of active profiles from the entire project hierarchy affects the effective build configuration.

      Returns:
      a non-null, possibly empty list of all active profiles from this project and its parents
      See Also: