Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void injectTransformedArtifacts(RepositorySystemSession session, MavenPro
}
}

TransformedArtifact createConsumerPomArtifact(
private TransformedArtifact createConsumerPomArtifact(
MavenProject project, Path consumer, RepositorySystemSession session) {
Path actual = project.getFile().toPath();
Path parent = project.getBaseDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.maven.api.Node;
import org.apache.maven.api.PathScope;
import org.apache.maven.api.SessionData;
import org.apache.maven.api.SourceRoot;
import org.apache.maven.api.feature.Features;
import org.apache.maven.api.model.Dependency;
import org.apache.maven.api.model.DistributionManagement;
Expand Down Expand Up @@ -342,7 +343,7 @@ static Model transformNonPom(Model model, MavenProject project) {
return model;
}

static Model transformBom(Model model, MavenProject project) {
private static Model transformBom(Model model, MavenProject project) {
boolean preserveModelVersion = model.isPreserveModelVersion();

Model.Builder builder = prune(
Expand Down Expand Up @@ -372,7 +373,13 @@ static Model transformPom(Model model, MavenProject project) {
if (model.getParent() != null) {
model = model.withParent(model.getParent().withRelativePath(null));
}

if (isModular(project)) {
// Build information are not really needed by consumers. Removed because the <source> elements
// are not compatible with Maven 4.0.0 model, and the remaining is not valid without them.
model = model.withBuild(null);
// Dependencies are dispatched by maven-jar-plugin in the POM generated for each module.
model = model.withDependencies(null);
}
if (!preserveModelVersion) {
model = model.withPreserveModelVersion(false);
String modelVersion = new MavenModelVersion().getModelVersion(model);
Expand All @@ -381,7 +388,22 @@ static Model transformPom(Model model, MavenProject project) {
return model;
}

static void warnNotDowngraded(MavenProject project) {
/**
* Whether the given project is modular. This method returns {@code true} it at least one enabled
* {@code <source>} element declares a Java modules. While modular and non-modular sources should
* not be mixed, this code is tolerant to such mixes because non-modular source elements may have
* been incorrectly generated by non module-aware codes, in which case they should be ignored.
*/
private static boolean isModular(MavenProject project) {
for (SourceRoot source : project.getSourceRoots()) {
if (source.enabled() && source.module().isPresent()) {
return true;
}
}
return false;
}

private static void warnNotDowngraded(MavenProject project) {
LOGGER.warn("The consumer POM for " + project.getId() + " cannot be downgraded to 4.0.0. "
+ "If you intent your build to be consumed with Maven 3 projects, you need to remove "
+ "the features that request a newer model version. If you're fine with having the "
Expand Down