<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>ca.weblite</groupId>
        <artifactId>ktswing-root</artifactId>
        <version>0.0.16</version>
    </parent>

    <artifactId>ktswing-main</artifactId>
    <packaging>jar</packaging>
    <name>ktswing-main</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- Kotlin stdlib for your main code -->
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
            <version>${kotlin.version}</version>
        </dependency>

        <!-- *** Depend on the codegen JAR *** -->
        <dependency>
            <groupId>ca.weblite</groupId>
            <artifactId>ktswing-codegen</artifactId>
            <version>0.0.16</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>RELEASE</version>
            <scope>test</scope>
        </dependency>

        <!-- JUnit, etc. if you have tests -->
    </dependencies>

    <build>
        <!-- Our main Kotlin sources are in src/main/kotlin -->
        <sourceDirectory>src/main/kotlin</sourceDirectory>

        <plugins>

            <!-- 1) Exec Maven Plugin: Run the code generator at generate-sources -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>

                            <!-- Our codegen class was compiled into codegen-1.0-SNAPSHOT.jar,
                                 so the plugin will automatically put it on the classpath
                                 because we declared the codegen dependency above. -->
                            <mainClass>ca.weblite.ktswing.codegen.CodeGenerator</mainClass>

                            <!-- Optionally pass an argument for the output directory -->
                            <arguments>
                                <argument>${project.build.directory}/generated-sources/kotlin</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- 2) Kotlin Maven Plugin: compile the main code + the generated code -->
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${kotlin.version}</version>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <jvmTarget>17</jvmTarget> <!-- or "21" if you want the latest -->
                            <!-- or use the 'release' parameter if you prefer -->
                            <sourceDirs>
                                <sourceDir>src/main/kotlin</sourceDir>
                                <sourceDir>${project.build.directory}/generated-sources/kotlin</sourceDir>
                            </sourceDirs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


        </plugins>
    </build>
</project>
