From 2b4f310707e5649c3a849faadd1ae6c283bd3e1e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?JB=20Onofr=C3=A9?= <jb.onofre@dremio.com>
Date: Wed, 12 Nov 2025 21:44:33 +0100
Subject: [PATCH 1/3] Deal with Kar packaging and cleanly attach artifact
 forcing pom packaging.

---
 .../karaf/tooling/features/GenerateDescriptorMojo.java   | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
index 553ce91826a..48299b3286c 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
@@ -346,10 +346,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
                     filter(inputFile, outputFile);
                     getLog().info("Generation not enabled");
                     getLog().info("Attaching artifact");
-                    //projectHelper.attachArtifact(project, attachmentArtifactType, attachmentArtifactClassifier, outputFile);
-                    Artifact artifact = factory.createArtifactWithClassifier(project.getGroupId(), project.getArtifactId(), project.getVersion(), attachmentArtifactType, attachmentArtifactClassifier);
-                    artifact.setFile(outputFile);
-                    project.setArtifact(artifact);
+                    projectHelper.attachArtifact(project, attachmentArtifactType, attachmentArtifactClassifier, outputFile);
+                    //Artifact artifact = factory.createArtifactWithClassifier(project.getGroupId(), project.getArtifactId(), project.getVersion(), attachmentArtifactType, attachmentArtifactClassifier);
+                    //artifact.setFile(outputFile);
+                    //project.setArtifact(artifact);
                     return;
                 }
             }
@@ -365,6 +365,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
                     writeFeatures(out);
                 }
                 getLog().info("Attaching features XML");
+                project.setPackaging("pom");
                 // now lets attach it
                 projectHelper.attachArtifact(project, attachmentArtifactType, attachmentArtifactClassifier, outputFile);
             } else {

From 905951314d3ccd4c119abbe76d2667c37408da7f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?JB=20Onofr=C3=A9?= <jbonofre@apache.org>
Date: Thu, 13 Nov 2025 16:44:21 +0100
Subject: [PATCH 2/3] Deal with feature packaging

---
 .../tooling/features/GenerateDescriptorMojo.java  | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
index 48299b3286c..79d85f7b163 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
@@ -364,10 +364,17 @@ public void execute() throws MojoExecutionException, MojoFailureException {
                 try (PrintStream out = new PrintStream(new FileOutputStream(outputFile))) {
                     writeFeatures(out);
                 }
-                getLog().info("Attaching features XML");
-                project.setPackaging("pom");
-                // now lets attach it
-                projectHelper.attachArtifact(project, attachmentArtifactType, attachmentArtifactClassifier, outputFile);
+                if (project.getPackaging().equals("feature") && enableGeneration) {
+                    getLog().info("Set artifact");
+                    Artifact artifact = factory.createArtifactWithClassifier(project.getGroupId(), project.getArtifactId(), project.getVersion(), attachmentArtifactType
+                    , FEATURE_CLASSIFIER);
+                    artifact.setFile(outputFile);
+                    project.setArtifact(artifact);
+                } else {
+                    getLog().info("Attaching features XML");
+                    // now lets attach it
+                    projectHelper.attachArtifact(project, attachmentArtifactType, attachmentArtifactClassifier, outputFile);
+                }
             } else {
                 throw new MojoExecutionException("Could not create directory for features file: " + dir);
             }

From 80e8cac840225c2c498482bc8e0806619d212b65 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?JB=20Onofr=C3=A9?= <jbonofre@apache.org>
Date: Thu, 13 Nov 2025 18:11:53 +0100
Subject: [PATCH 3/3] Also deal with packaging in the case generation is not
 enabled.

---
 .../tooling/features/GenerateDescriptorMojo.java      | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
index 79d85f7b163..63575529691 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
@@ -346,10 +346,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
                     filter(inputFile, outputFile);
                     getLog().info("Generation not enabled");
                     getLog().info("Attaching artifact");
-                    projectHelper.attachArtifact(project, attachmentArtifactType, attachmentArtifactClassifier, outputFile);
-                    //Artifact artifact = factory.createArtifactWithClassifier(project.getGroupId(), project.getArtifactId(), project.getVersion(), attachmentArtifactType, attachmentArtifactClassifier);
-                    //artifact.setFile(outputFile);
-                    //project.setArtifact(artifact);
+                    if (project.getPackaging().equals("feature")) {
+                        Artifact artifact = factory.createArtifactWithClassifier(project.getGroupId(), project.getArtifactId(), project.getVersion(), attachmentArtifactType, attachmentArtifactClassifier);
+                        artifact.setFile(outputFile);
+                        project.setArtifact(artifact);
+                    } else {
+                        projectHelper.attachArtifact(project, attachmentArtifactType, attachmentArtifactClassifier, outputFile);
+                    }
                     return;
                 }
             }
