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 @@ -1423,7 +1423,14 @@ private Model readEffectiveModel() throws ModelBuilderException {
// Mixins
for (Mixin mixin : model.getMixins()) {
Model parent = resolveParent(model, mixin, profileActivationContext, parentChain);
// Merge mixin into model
model = inheritanceAssembler.assembleModelInheritance(model, parent, request, this);
// Ensure mixin properties override any previously inherited properties
// This is necessary because normal inheritance gives child precedence, but for mixins
// we want the mixin to take precedence over inherited parent properties
Map<String, String> mergedProperties = new java.util.HashMap<>(model.getProperties());
mergedProperties.putAll(parent.getProperties());
model = model.withProperties(mergedProperties);
}

// model normalization
Expand Down Expand Up @@ -1901,7 +1908,12 @@ protected void mergeModel_Subprojects(
Model parent = defaultInheritanceAssembler.assembleModelInheritance(raw, parentData, request, this);
for (Mixin mixin : parent.getMixins()) {
Model parentModel = resolveParent(parent, mixin, childProfileActivationContext, parentChain);
// Merge mixin into parent
parent = defaultInheritanceAssembler.assembleModelInheritance(parent, parentModel, request, this);
// Ensure mixin properties override any previously inherited properties
Map<String, String> mergedProperties = new java.util.HashMap<>(parent.getProperties());
mergedProperties.putAll(parentModel.getProperties());
parent = parent.withProperties(mergedProperties);
}

// 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,49 @@
/*
* 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 {

@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