|
43 | 43 |
|
44 | 44 | import io.openliberty.tools.common.plugins.util.LibertyPropFilesUtility; |
45 | 45 | import io.openliberty.tools.maven.utils.CommonLogger; |
| 46 | +import org.apache.commons.lang3.StringUtils; |
46 | 47 | import org.apache.maven.artifact.Artifact; |
47 | 48 | import org.apache.maven.artifact.DependencyResolutionRequiredException; |
48 | 49 | import org.apache.maven.execution.MavenSession; |
@@ -520,7 +521,16 @@ public ServerTask getServerTask() throws Exception { |
520 | 521 |
|
521 | 522 | // set environment variables for server start task |
522 | 523 | serverTask.setOperation("debug"); |
523 | | - serverTask.setEnvironmentVariables(getDebugEnvironmentVariables()); |
| 524 | + |
| 525 | + // Merge toolchain environment with debug environment |
| 526 | + Map<String, String> debugEnv = getDebugEnvironmentVariables(); |
| 527 | + if (toolchain != null) { |
| 528 | + String toolchainJavaHome = getJdkHomeFromToolchain(toolchain); |
| 529 | + if (toolchainJavaHome != null) { |
| 530 | + debugEnv.put("JAVA_HOME", toolchainJavaHome); |
| 531 | + } |
| 532 | + } |
| 533 | + serverTask.setEnvironmentVariables(debugEnv); |
524 | 534 | } else { |
525 | 535 | serverTask.setOperation("run"); |
526 | 536 | } |
@@ -1740,24 +1750,67 @@ private JavaCompilerOptions getMavenCompilerOptions(MavenProject currentProject) |
1740 | 1750 | String release = getCompilerOption(configuration, "release", "maven.compiler.release", currentProject); |
1741 | 1751 | String source = getCompilerOption(configuration, "source", "maven.compiler.source", currentProject); |
1742 | 1752 | String target = getCompilerOption(configuration, "target", "maven.compiler.target", currentProject); |
| 1753 | + |
| 1754 | + // Fetch the toolchain version configured for the project |
| 1755 | + String jdkToolchainVersion = jdkToolchain != null ? jdkToolchain.get("version") : null; |
| 1756 | + if (StringUtils.isNotEmpty(jdkToolchainVersion)) { |
| 1757 | + String compilerJdkToolchainVersion = null; |
| 1758 | + if (configuration != null) { |
| 1759 | + Xpp3Dom compilerJdkToolchain = configuration.getChild("jdkToolchain"); |
| 1760 | + if (compilerJdkToolchain != null) { |
| 1761 | + Xpp3Dom versionChild = compilerJdkToolchain.getChild("version"); |
| 1762 | + if (versionChild != null) { |
| 1763 | + compilerJdkToolchainVersion = StringUtils.trimToNull(versionChild.getValue()); |
| 1764 | + } |
| 1765 | + } |
| 1766 | + } |
| 1767 | + |
| 1768 | + if (compilerJdkToolchainVersion == null) { |
| 1769 | + getLog().debug("Maven compiler plugin is not configured with a jdkToolchain. " |
| 1770 | + + "Using liberty-maven-plugin jdkToolchain configuration for Java compiler options."); |
| 1771 | + } else { |
| 1772 | + if (jdkToolchainVersion.equals(compilerJdkToolchainVersion)) { |
| 1773 | + getLog().info("Liberty Maven Plugin jdkToolchain configuration matches the Maven Compiler Plugin jdkToolchain " |
| 1774 | + + "configuration: version " + jdkToolchainVersion + "."); |
| 1775 | + } else { |
| 1776 | + getLog().debug("Liberty Maven Plugin jdkToolchain configuration (version " + jdkToolchainVersion |
| 1777 | + + ") does not match the Maven Compiler Plugin jdkToolchain configuration " |
| 1778 | + + "(version " + compilerJdkToolchainVersion |
| 1779 | + + "). The project-level Maven Compiler Plugin toolchain configuration will be used for compilation."); |
| 1780 | + } |
| 1781 | + } |
| 1782 | + } |
| 1783 | + |
1743 | 1784 | if (release != null) { |
1744 | | - getLog().debug("Setting compiler release to " + release); |
| 1785 | + if (StringUtils.isNotEmpty(jdkToolchainVersion)) { |
| 1786 | + getLog().debug("Setting compiler release to toolchain JDK version " + jdkToolchainVersion); |
| 1787 | + } else { |
| 1788 | + getLog().debug("Setting compiler release to " + release); |
| 1789 | + } |
1745 | 1790 | if (source != null) { |
1746 | 1791 | getLog().debug("Compiler option source will be ignored since release is specified"); |
1747 | 1792 | } |
1748 | 1793 | if (target != null) { |
1749 | 1794 | getLog().debug("Compiler option target will be ignored since release is specified"); |
1750 | 1795 | } |
1751 | | - compilerOptions.setRelease(release); |
| 1796 | + compilerOptions.setRelease(StringUtils.isNotEmpty(jdkToolchainVersion) ? jdkToolchainVersion : release); |
1752 | 1797 | } else { |
1753 | 1798 | // add source and target only if release is not set |
1754 | 1799 | if (source != null) { |
1755 | | - getLog().debug("Setting compiler source to " + source); |
1756 | | - compilerOptions.setSource(source); |
| 1800 | + if (StringUtils.isNotEmpty(jdkToolchainVersion)) { |
| 1801 | + getLog().debug("Setting compiler source to toolchain JDK version " + jdkToolchainVersion); |
| 1802 | + } else { |
| 1803 | + getLog().debug("Setting compiler source to " + source); |
| 1804 | + } |
| 1805 | + compilerOptions.setSource(StringUtils.isNotEmpty(jdkToolchainVersion) ? jdkToolchainVersion : source); |
1757 | 1806 | } |
1758 | 1807 | if (target != null) { |
1759 | | - getLog().debug("Setting compiler target to " + target); |
1760 | | - compilerOptions.setTarget(target); |
| 1808 | + if (StringUtils.isNotEmpty(jdkToolchainVersion)) { |
| 1809 | + getLog().debug("Setting compiler target to toolchain JDK version " + jdkToolchainVersion); |
| 1810 | + } else { |
| 1811 | + getLog().debug("Setting compiler target to " + target); |
| 1812 | + } |
| 1813 | + compilerOptions.setTarget(StringUtils.isNotEmpty(jdkToolchainVersion) ? jdkToolchainVersion : target); |
1761 | 1814 | } |
1762 | 1815 | } |
1763 | 1816 |
|
|
0 commit comments