0

Is it possible to override the auto-generated mule-artifact.json when creating a custom mule extension?

William
  • 91
  • 1
  • 10

2 Answers2

1

Yes it can be overridden, you need to place your custom mule-artifact.json under META-INF/mule-artifact/mule-artifact.json inside your project's src/main/resources.

Harshank Bansal
  • 2,798
  • 2
  • 7
  • 22
  • I have my mule-artifact.json in `${project.home}/src/main/resources/META-INF/mule-artifact`, but when I run `maven test` a generated version is created in `target\classes\META-INF\mule-artifact`. When I run `maven generate-sources`, my version is copied into `target\classes\META-INF\mule-artifact`. – William Sep 14 '22 at 19:35
  • Not really sure about test, maybe you need to maintain a copy of it under `src/test/resources` ? Not really sure though. – Harshank Bansal Sep 14 '22 at 19:44
  • Out of curiosity, what is it that you need a custom artifact json for test? I have mostly seen overriding it to `export` your certain resources, but I don't think you will need to export anything for test. I could be wrong. – Harshank Bansal Sep 14 '22 at 19:46
  • I have packages I need to export for testing and deployment. In my test, I instantiate the custom classes, but since they are part of a dependency, they are not visible. – William Sep 14 '22 at 19:52
  • You should have provided the context in your question. @HarshankBansal has answered the question as it is. You should create a new question for the test issue providing more details and accept this one. – aled Sep 14 '22 at 23:10
  • I agree with aled, since your problem seems like it needs more background. What I did not understand is you said these "custom classes" are part of dependency. How are they part of dependency? Are your tests for your custom extension written in a separate project? – Harshank Bansal Sep 15 '22 at 07:31
  • @aled Placing the mule-artifact.json file in `META-INF/mule-artifact` doesn't solve the problem. My custom mule-artifact.json does not get packaged into the jar. I was using the test case as an example of the generated file not being overridden. – William Sep 15 '22 at 12:40
  • It seems that somewhere between the `generate-sources` and `test` phases the user's file is being replaced by a generated file. – William Sep 15 '22 at 12:50
  • 1
    @user1932673 `mvn test` has nothing to do with how the package will be generated. If you really want to see how it will actually look like, you can use `mvn clean install` instead – Harshank Bansal Sep 15 '22 at 12:57
  • I'm not running `mvn test`. I am running `mvn clean install` and the jar file does not contain my `mule-artifact.json`. The file is being replaced with an auto-generated file. Either way, the command fails at the test phase because the custom file is overwritten. If I skip the test phase, the generated jar does not contain my file, but an auto-generated file. – William Sep 15 '22 at 13:25
  • What is the `mule-extensions-maven-plugin` verison that you are using? I tried with `1.1.5` and it worked for me – Harshank Bansal Sep 15 '22 at 13:50
  • `mule-extensions-maven-plugin` version `1.1.6`. This is the version included in `mule-modules-parent 1.1.9` and `1.1.3`. I just tried with `mule-extensions-maven-plugin` version `1.1.6` and the custom `mule-artifact.json` is replaced. I ran maven up to just before `mule-extensions-maven-plugin` executes and `target\classes\META-INF\mule-artifact\mule-artifact.json` is my custom file. I then ran maven up to and including `mule-extensions-maven-plugin` and my file has been replaced with the generated one. – William Sep 15 '22 at 14:46
  • Seems like a bug then, maybe you can try to file a bug. Or if you have the license, you can create a support ticket. – Harshank Bansal Sep 15 '22 at 14:57
0

A work around for overriding the auto-generated mule-artifact.jsonis to add maven-resources-plugin to your pom and run it after the mule-extensions-maven-plugin creates the file. Here is what I used:

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-custom-artifact</id>
            <phase>process-classes</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${basedir}/target</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/main/resources/META-INF/mule-artifact</directory>
                        <targetPath>classes/META-INF/mule-artifact</targetPath>
                    </resource>
                </resources>
                <overwrite>true</overwrite>
            </configuration>
        </execution>
    </executions>
</plugin>
William
  • 91
  • 1
  • 10