Maven2 compatibility layer providing legacy APIs for Maven3 environment.
—
Legacy project building system for constructing Maven projects from POM files with Maven2 compatibility patterns.
Main interface for building Maven projects from POM files and artifacts.
/**
* Interface for building Maven projects from POM files and artifacts
* @deprecated Use ProjectBuilder instead
*/
@Deprecated
public interface MavenProjectBuilder {
/**
* Builds a Maven project from a POM file
* @param pom POM file to build from
* @param configuration builder configuration
* @return constructed MavenProject
* @throws ProjectBuildingException if building fails
*/
MavenProject build(File pom, ProjectBuilderConfiguration configuration)
throws ProjectBuildingException;
/**
* Builds a Maven project from an artifact in repositories
* @param artifact artifact to build project for
* @param remoteRepositories remote repositories to search
* @param localRepository local repository
* @return constructed MavenProject
* @throws ProjectBuildingException if building fails
*/
MavenProject buildFromRepository(Artifact artifact, List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository)
throws ProjectBuildingException;
/**
* Builds a standalone super project
* @param configuration builder configuration
* @return constructed super MavenProject
* @throws ProjectBuildingException if building fails
*/
MavenProject buildStandaloneSuperProject(ProjectBuilderConfiguration configuration)
throws ProjectBuildingException;
/**
* Builds project with dependencies resolved (deprecated)
* @param pom POM file to build from
* @param localRepository local repository
* @param globalProfileManager profile manager for activation
* @return constructed MavenProject with dependencies
* @throws ProjectBuildingException if building fails
* @deprecated Use build(File, ProjectBuilderConfiguration) instead
*/
@Deprecated
MavenProject buildWithDependencies(File pom, ArtifactRepository localRepository,
ProfileManager globalProfileManager)
throws ProjectBuildingException;
}Default implementation of MavenProjectBuilder.
/**
* Default implementation of MavenProjectBuilder
*/
public class DefaultMavenProjectBuilder implements MavenProjectBuilder {
/**
* Builds a Maven project from a POM file
*/
public MavenProject build(File pom, ProjectBuilderConfiguration configuration)
throws ProjectBuildingException;
/**
* Builds a Maven project from an artifact in repositories
*/
public MavenProject buildFromRepository(Artifact artifact, List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository)
throws ProjectBuildingException;
/**
* Builds a standalone super project
*/
public MavenProject buildStandaloneSuperProject(ProjectBuilderConfiguration configuration)
throws ProjectBuildingException;
}Interface for configuring project building behavior.
/**
* Configuration interface for project building behavior
*/
public interface ProjectBuilderConfiguration {
/**
* Gets the local repository
* @return local ArtifactRepository
*/
ArtifactRepository getLocalRepository();
/**
* Sets the local repository
* @param localRepository local repository to use
*/
void setLocalRepository(ArtifactRepository localRepository);
/**
* Gets remote repositories
* @return List of remote ArtifactRepository objects
*/
List<ArtifactRepository> getRemoteRepositories();
/**
* Sets remote repositories
* @param remoteRepositories list of remote repositories
*/
void setRemoteRepositories(List<ArtifactRepository> remoteRepositories);
/**
* Gets the profile manager
* @return ProfileManager for profile activation
*/
ProfileManager getGlobalProfileManager();
/**
* Sets the profile manager
* @param globalProfileManager profile manager to use
*/
void setGlobalProfileManager(ProfileManager globalProfileManager);
/**
* Gets build start time
* @return Date when build started
*/
Date getBuildStartTime();
/**
* Sets build start time
* @param buildStartTime build start timestamp
*/
void setBuildStartTime(Date buildStartTime);
/**
* Gets user properties
* @return Properties from user input
*/
Properties getUserProperties();
/**
* Sets user properties
* @param userProperties user-defined properties
*/
void setUserProperties(Properties userProperties);
/**
* Gets execution properties
* @return Properties for execution context
*/
Properties getExecutionProperties();
/**
* Sets execution properties
* @param executionProperties execution context properties
*/
void setExecutionProperties(Properties executionProperties);
}Default implementation of ProjectBuilderConfiguration.
/**
* Default implementation of ProjectBuilderConfiguration
*/
public class DefaultProjectBuilderConfiguration implements ProjectBuilderConfiguration {
/**
* Creates default configuration
*/
public DefaultProjectBuilderConfiguration();
/**
* Gets the local repository
*/
public ArtifactRepository getLocalRepository();
/**
* Sets the local repository
*/
public void setLocalRepository(ArtifactRepository localRepository);
/**
* Gets remote repositories
*/
public List<ArtifactRepository> getRemoteRepositories();
/**
* Sets remote repositories
*/
public void setRemoteRepositories(List<ArtifactRepository> remoteRepositories);
/**
* Gets the profile manager
*/
public ProfileManager getGlobalProfileManager();
/**
* Sets the profile manager
*/
public void setGlobalProfileManager(ProfileManager globalProfileManager);
/**
* Gets build start time
*/
public Date getBuildStartTime();
/**
* Sets build start time
*/
public void setBuildStartTime(Date buildStartTime);
/**
* Gets user properties
*/
public Properties getUserProperties();
/**
* Sets user properties
*/
public void setUserProperties(Properties userProperties);
/**
* Gets execution properties
*/
public Properties getExecutionProperties();
/**
* Sets execution properties
*/
public void setExecutionProperties(Properties executionProperties);
}Interface for interpolating variables in Maven models.
/**
* Interface for interpolating variables in Maven models
* @deprecated Use newer model building APIs
*/
@Deprecated
public interface ModelInterpolator {
/**
* Default timestamp format for build timestamps
*/
String DEFAULT_BUILD_TIMESTAMP_FORMAT = "yyyyMMdd-HHmm";
/**
* Interpolates variables in a Maven model
* @param model model to interpolate
* @param projectDir project directory for relative path resolution
* @param config project builder configuration
* @param debugEnabled whether debug output is enabled
* @return interpolated model
* @throws ModelInterpolationException if interpolation fails
*/
Model interpolate(Model model, File projectDir, ProjectBuilderConfiguration config, boolean debugEnabled)
throws ModelInterpolationException;
/**
* Interpolates variables in a string
* @param src source string to interpolate
* @param model model providing variable context
* @param projectDir project directory
* @param config project builder configuration
* @param debugEnabled whether debug output is enabled
* @return interpolated string
* @throws ModelInterpolationException if interpolation fails
*/
String interpolate(String src, Model model, File projectDir, ProjectBuilderConfiguration config,
boolean debugEnabled) throws ModelInterpolationException;
}Interface for validating Maven project models.
/**
* Interface for validating Maven project models
* @deprecated Use newer model validation APIs
*/
@Deprecated
public interface ModelValidator {
/**
* Role constant for Plexus component lookup
*/
String ROLE = ModelValidator.class.getName();
/**
* Validates a Maven model
* @param model model to validate
* @return validation result with any errors or warnings
*/
ModelValidationResult validate(Model model);
}Container for model validation results.
/**
* Container for model validation results
*/
public class ModelValidationResult {
/**
* Creates empty validation result
*/
public ModelValidationResult();
/**
* Gets number of validation messages
* @return count of validation messages
*/
public int getMessageCount();
/**
* Gets validation messages
* @return List of validation message strings
*/
public List<String> getMessages();
/**
* Adds a validation message
* @param message validation message to add
*/
public void addMessage(String message);
/**
* Checks if validation has any messages
* @return true if there are validation messages
*/
public boolean hasMessages();
}import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.DefaultMavenProjectBuilder;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
import org.apache.maven.project.MavenProject;
// Create project builder
MavenProjectBuilder builder = new DefaultMavenProjectBuilder();
// Configure builder
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration();
config.setLocalRepository(localRepository);
config.setRemoteRepositories(remoteRepositories);
config.setGlobalProfileManager(profileManager);
config.setBuildStartTime(new Date());
try {
// Build project from POM
File pomFile = new File("pom.xml");
MavenProject project = builder.build(pomFile, config);
System.out.println("Built project: " + project.getArtifactId());
System.out.println("Version: " + project.getVersion());
System.out.println("Dependencies: " + project.getDependencies().size());
} catch (ProjectBuildingException e) {
System.err.println("Project building failed: " + e.getMessage());
}// Build project from artifact in repository
Artifact projectArtifact = // ... create or obtain artifact
List<ArtifactRepository> remoteRepos = // ... configure remote repositories
try {
MavenProject project = builder.buildFromRepository(
projectArtifact,
remoteRepos,
localRepository
);
System.out.println("Built project from artifact: " + project.getArtifactId());
} catch (ProjectBuildingException e) {
System.err.println("Failed to build from repository: " + e.getMessage());
}// Build standalone super project
try {
MavenProject superProject = builder.buildStandaloneSuperProject(config);
System.out.println("Created super project: " + superProject.getArtifactId());
} catch (ProjectBuildingException e) {
System.err.println("Super project creation failed: " + e.getMessage());
}import org.apache.maven.project.interpolation.ModelInterpolator;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.model.Model;
// Interpolate model variables
ModelInterpolator interpolator = // ... get interpolator instance
Model model = // ... load model
File projectDir = new File(".");
try {
Model interpolatedModel = interpolator.interpolate(
model,
projectDir,
config,
false // debug disabled
);
System.out.println("Model interpolated successfully");
// Interpolate individual string
String interpolatedString = interpolator.interpolate(
"${project.version}",
model,
projectDir,
config,
false
);
System.out.println("Interpolated version: " + interpolatedString);
} catch (ModelInterpolationException e) {
System.err.println("Interpolation failed: " + e.getMessage());
}import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.project.validation.ModelValidationResult;
// Validate model
ModelValidator validator = // ... get validator instance
Model model = // ... load model
ModelValidationResult result = validator.validate(model);
if (result.hasMessages()) {
System.out.println("Validation issues found:");
for (String message : result.getMessages()) {
System.out.println(" - " + message);
}
} else {
System.out.println("Model validation passed");
}public MavenProject buildProjectComplete(File pomFile) {
try {
// Create and configure builder
MavenProjectBuilder builder = new DefaultMavenProjectBuilder();
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration();
// Set up repositories
config.setLocalRepository(createLocalRepository());
config.setRemoteRepositories(createRemoteRepositories());
// Set up profile management
ProfileManager profileManager = new DefaultProfileManager();
config.setGlobalProfileManager(profileManager);
// Set build properties
config.setBuildStartTime(new Date());
config.setUserProperties(System.getProperties());
// Build the project
MavenProject project = builder.build(pomFile, config);
// Validate the built project
validateProject(project);
return project;
} catch (ProjectBuildingException e) {
throw new RuntimeException("Failed to build project", e);
}
}
private void validateProject(MavenProject project) {
ModelValidator validator = // ... get validator
ModelValidationResult result = validator.validate(project.getModel());
if (result.hasMessages()) {
System.out.println("Project validation warnings:");
result.getMessages().forEach(msg -> System.out.println(" " + msg));
}
}/**
* Exception thrown when project building fails
*/
public class ProjectBuildingException extends Exception {
/**
* Creates exception with message
* @param message error message
*/
public ProjectBuildingException(String message);
/**
* Creates exception with message and cause
* @param message error message
* @param cause underlying cause
*/
public ProjectBuildingException(String message, Throwable cause);
}/**
* Exception thrown when model interpolation fails
*/
public class ModelInterpolationException extends Exception {
/**
* Creates exception with message
* @param message error message
*/
public ModelInterpolationException(String message);
/**
* Creates exception with message and cause
* @param message error message
* @param cause underlying cause
*/
public ModelInterpolationException(String message, Throwable cause);
}The project building system in maven-compat is deprecated. Modern Maven 3.x applications should use:
org.apache.maven.project.ProjectBuilder instead of MavenProjectBuilderorg.apache.maven.project.ProjectBuildingRequest instead of ProjectBuilderConfigurationorg.apache.maven.model.building.ModelBuilder for model processingInstall with Tessl CLI
npx tessl i tessl/maven-org-apache-maven--maven-compat