Add an integration test of using modular artifacts with jlink in JDK9

Setup maven plugin integration test execution with JDK9 as java home.
This commit is contained in:
Ilya Gorbunov
2019-01-31 06:18:46 +03:00
parent 804e03379d
commit 9c7a785d78
7 changed files with 269 additions and 2 deletions
@@ -107,8 +107,6 @@
<artifactId>maven-invoker-plugin</artifactId>
<version>2.0.0</version>
<configuration>
<projectsDirectory>src/it</projectsDirectory>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
</pomIncludes>
@@ -131,6 +129,10 @@
<artifact>org.jetbrains.kotlin:kotlin-stdlib-jdk7:${project.version}</artifact>
<artifact>org.jetbrains.kotlin:kotlin-stdlib-jdk8:${project.version}</artifact>
<artifact>org.jetbrains.kotlin:kotlin-reflect:${project.version}</artifact>
<artifact>org.jetbrains.kotlin:kotlin-stdlib:${project.version}:jar:modular</artifact>
<artifact>org.jetbrains.kotlin:kotlin-stdlib-jdk7:${project.version}:jar:modular</artifact>
<artifact>org.jetbrains.kotlin:kotlin-stdlib-jdk8:${project.version}:jar:modular</artifact>
<artifact>org.jetbrains.kotlin:kotlin-reflect:${project.version}:jar:modular</artifact>
<artifact>org.jetbrains.kotlin:kotlin-test-common:${project.version}</artifact>
<artifact>org.jetbrains.kotlin:kotlin-test-annotations-common:${project.version}</artifact>
<artifact>org.jetbrains.kotlin:kotlin-test:${project.version}</artifact>
@@ -152,12 +154,28 @@
<executions>
<execution>
<id>integration-test</id>
<configuration>
<projectsDirectory>src/it</projectsDirectory>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
</configuration>
<!--<phase>package</phase>-->
<goals>
<goal>install</goal>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>integration-test-java9</id>
<configuration>
<projectsDirectory>src/it/java9</projectsDirectory>
<cloneProjectsTo>${project.build.directory}/it/java9</cloneProjectsTo>
<javaHome>${env.JDK_9}</javaHome>
</configuration>
<goals>
<goal>install</goal>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>test-mavenModular</artifactId>
<groupId>org.test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>test-mavenModularApp</artifactId>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,6 @@
module org.test.modularApp {
requires transitive kotlin.stdlib;
requires kotlin.stdlib.jdk8;
exports org.test.modularApp;
}
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.test.modularApp
import kotlin.math.*
import kotlin.random.*
fun main() {
println(Random.nextDouble(abs(sin(PI) + cos(PI))))
}
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>test-mavenModular</artifactId>
<groupId>org.test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>test-mavenModular-jlinked</artifactId>
<packaging>jar</packaging>
<dependencies>
<!--
Here goes a boilerplate part: we need to exclude all kotlin non-modular library artifacts coming
as a transitive dependency from every dependency of this project.
-->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
<classifier>modular</classifier>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-common</artifactId>
</exclusion>
<exclusion>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk7</artifactId>
<version>${kotlin.version}</version>
<classifier>modular</classifier>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
<classifier>modular</classifier>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk7</artifactId>
</exclusion>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.test</groupId>
<artifactId>test-mavenModularApp</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<!-- We need to remove the default execution of maven-jar-plugin, otherwise there will be a clash of
the artifacts produced by this plugin and by maven-jlink-plugin -->
<executions>
<execution>
<id>default-jar</id>
<phase/>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jlink-plugin</artifactId>
<version>3.0.0-alpha-1</version>
<executions>
<execution>
<goals><goal>jlink</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>test-mavenModular</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>mavenModular Example</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.12</junit.version>
</properties>
<modules>
<module>app</module>
<module>jlinked</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.9</source>
<target>1.9</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
@@ -0,0 +1,22 @@
import java.io.*;
File file = new File(basedir, "jlinked/target/maven-jlink/release")
if (!file.exists() || !file.isFile()) {
throw new FileNotFoundException("Could not find generated image release file: " + file)
}
def releaseProps = new Properties()
releaseProps.load(new FileReader(file))
def modules = releaseProps.getProperty("MODULES")
assert modules != null : "MODULES property missing"
if (modules.startsWith("\"") && modules.endsWith("\"")) modules = modules[1..-2]
println("jlink has built an image with modules: $modules")
def moduleSet = modules.tokenize(" ").toSet()
for (module in ["java.base", "kotlin.stdlib", "kotlin.stdlib.jdk7", "kotlin.stdlib.jdk8", "org.test.modularApp"]) {
assert moduleSet.contains(module) : "Expected to find $module in image modules: $modules"
}