<?xml version="1.0" encoding="UTF-8"?>
<!--
    Licensed 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.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.eclipse.microprofile.config</groupId>
        <artifactId>microprofile-config-parent</artifactId>
        <version>3.1.2</version>
    </parent>

    <artifactId>microprofile-config-api</artifactId>
    <name>MicroProfile Config API</name>
    <description>MicroProfile Config :: API</description>

    <dependencies>
        <dependency>
            <groupId>jakarta.enterprise</groupId>
            <artifactId>jakarta.enterprise.cdi-api</artifactId>
        </dependency>
        <dependency>
            <groupId>biz.aQute.bnd</groupId>
            <artifactId>biz.aQute.bnd.annotation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.service.cdi</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Automatic-Module-Name>org.eclipse.microprofile.config</Automatic-Module-Name>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <!--
                        The module descriptor is compiled in a dedicated execution, patched onto the
                        already compiled classes. This keeps the main compilation unchanged (class path)
                        and avoids requiring the OSGi/bnd annotation jars referenced by package-info.java,
                        which are compile-time only and ship no module descriptor.
                    -->
                    <execution>
                        <id>compile-module-info</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <!-- module-info requires at least Java 9; the other classes stay on the project baseline. -->
                            <release>9</release>
                            <!--
                                Restricts this execution to the descriptor only (maven-compiler-plugin 3.x honours
                                this parameter): src/main/java is not recompiled and keeps its Java 8 bytecode.
                            -->
                            <compileSourceRoots>
                                <compileSourceRoot>${project.basedir}/src/main/module-info</compileSourceRoot>
                            </compileSourceRoots>
                            <compilerArgs>
                                <arg>--patch-module</arg>
                                <arg>org.eclipse.microprofile.config=${project.build.outputDirectory}</arg>
                            </compilerArgs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <!--
                        Keep javadoc in class path mode: a module-info.java at the root of a source path would switch
                        it to module mode, so only the regular sources are documented.
                    -->
                    <legacyMode>true</legacyMode>
                    <sourcepath>${project.build.sourceDirectory}</sourcepath>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <!--
                        Register the descriptor source root only once compilation is over, so that the
                        sources jar ships module-info.java while the default compilation keeps ignoring it.
                    -->
                    <execution>
                        <id>add-module-info-source</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.basedir}/src/main/module-info</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
