Skip to content
Draft
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 @@ -73,6 +73,20 @@ public Model assembleModelInheritance(
return merger.merge(child, parent, false, hints);
}

// Package-private overload to allow callers (e.g., for mixins) to control source dominance
Model assembleModelInheritance(
Model child,
Model parent,
ModelBuilderRequest request,
ModelProblemCollector problems,
boolean sourceDominant) {
Map<Object, Object> hints = new HashMap<>();
String childPath = child.getProperties().getOrDefault(CHILD_DIRECTORY_PROPERTY, child.getArtifactId());
hints.put(CHILD_DIRECTORY, childPath);
hints.put(MavenModelMerger.CHILD_PATH_ADJUSTMENT, getChildPathAdjustment(child, parent, childPath));
return merger.merge(child, parent, sourceDominant, hints);
}

/**
* Calculates the relative path from the base directory of the parent to the parent directory of the base directory
* of the child. The general idea is to adjust inherited URLs to match the project layout (in SCM).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,12 @@ private Model readEffectiveModel() throws ModelBuilderException {
// Mixins
for (Mixin mixin : model.getMixins()) {
Model parent = resolveParent(model, mixin, profileActivationContext);
model = inheritanceAssembler.assembleModelInheritance(model, parent, request, this);
// For mixins, ensure source (mixin) is dominant so its properties override previously inherited ones
if (inheritanceAssembler instanceof DefaultInheritanceAssembler dia) {
model = dia.assembleModelInheritance(model, parent, request, this, true);
} else {
model = inheritanceAssembler.assembleModelInheritance(model, parent, request, this);
}
}

// model normalization
Expand Down Expand Up @@ -1625,7 +1630,8 @@ protected void mergeModel_Subprojects(
Model parent = defaultInheritanceAssembler.assembleModelInheritance(raw, parentData, request, this);
for (Mixin mixin : parent.getMixins()) {
Model parentModel = resolveParent(parent, mixin, childProfileActivationContext);
parent = defaultInheritanceAssembler.assembleModelInheritance(parent, parentModel, request, this);
// For mixins applied to parentData when building parent, make mixin dominant
parent = defaultInheritanceAssembler.assembleModelInheritance(parent, parentModel, request, this, true);
}

// Profile injection SHOULD be performed on parent models to ensure
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.it;

import java.io.File;
import java.nio.file.Files;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* MNG-11133: Mixins should override properties inherited from parent.
*/
public class MavenITmng11133MixinsPrecedenceTest extends AbstractMavenIntegrationTestCase {

public MavenITmng11133MixinsPrecedenceTest() {
super("4.1.0"); // affected since 4.1.0+
}

@Test
public void testMixinOverridesParentProperty() throws Exception {
File testDir = extractResources("/mng-11133-mixins/project");

Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteDirectory("target");
verifier.addCliArgument("help:effective-pom");
verifier.addCliArgument("-Doutput=target/effective-pom.xml");
verifier.execute();
verifier.verifyErrorFreeLog();

verifier.verifyFilePresent("target/effective-pom.xml");
String effectivePom = Files.readString(new File(testDir, "target/effective-pom.xml").toPath());
assertTrue(effectivePom.contains("<maven.compiler.release>21</maven.compiler.release>"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.2.0">
<modelVersion>4.2.0</modelVersion>

<groupId>org.apache.maven.its.mng11133</groupId>
<artifactId>mixin-jdk-21</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

<properties>
<maven.compiler.release>21</maven.compiler.release>
</properties>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.2.0 https://maven.apache.org/xsd/maven-4.2.0.xsd">
<modelVersion>4.2.0</modelVersion>

<groupId>org.apache.maven.its.mng11133</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<properties>
<maven.compiler.release>11</maven.compiler.release>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.2.0 https://maven.apache.org/xsd/maven-4.2.0.xsd">
<modelVersion>4.2.0</modelVersion>

<parent>
<groupId>org.apache.maven.its.mng11133</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

<groupId>org.apache.maven.its.mng11133</groupId>
<artifactId>project</artifactId>
<version>1.0</version>

<mixins>
<mixin>
<relativePath>../mixins/mixin.xml</relativePath>
</mixin>
</mixins>
</project>
Loading