[
https://issues.apache.org/jira/browse/MNG-6648?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16827637#comment-16827637
]
Alix Lourme commented on MNG-6648:
----------------------------------
The use-case is (for sample) to use JDK 11 if enforced by command line
parameter, or JDK 1.8 if JAVA_HOME empty.
Command line: {{mvn -Dmaven.jdk=11 clean}}
Could be done with a script like:
{code:title=mavenre_pre.cmd|borderStyle=solid}
@echo off
rem Define JDK 1.7 if enforced as command line parameter
echo "%*" | findstr "maven.jdk=7" >NUL
IF %ERRORLEVEL% EQU 0 (set JAVA_HOME=c:\somewhere\jdk1.7)
rem Define JDK 11 if enforced as command line parameter
echo "%*" | findstr "maven.jdk=11" >NUL
IF %ERRORLEVEL% EQU 0 (set JAVA_HOME=c:\somewhere\jdk11)
rem If JAVA_HOME empty, force to JDK 1.8 (avoiding using "C:\Program Files
(x86)\Java" if dos-cmd or the one of IDE runtime)
IF "%JAVA_HOME%" == "" (set JAVA_HOME=c:\somewhere\jdk1.8)
rem Debug for result check
echo Current JAVA_HOME: %JAVA_HOME%
{code}
I agree that {{set JAVA_HOME=c:\somewhere\jdkXX && mvn clean}} is working on
Windows, but when Maven used in command line.
If you bind a Maven external distribution in your IDE and execute it with
integrated runner, you should have to custom dedicated runner (sysenv
properties, ...) to enforce JDK.
> Add command line parameters in 'mavenrc_pre' script
> ---------------------------------------------------
>
> Key: MNG-6648
> URL: https://issues.apache.org/jira/browse/MNG-6648
> Project: Maven
> Issue Type: Improvement
> Components: Command Line
> Affects Versions: 3.6.0, 3.6.1
> Reporter: Alix Lourme
> Priority: Major
> Labels: command-line, script
> Fix For: waiting-for-feedback
>
>
> Hello,
> In some corner-case, you could have to run Maven with a custom {{JAVA_HOME}}
> (JDK v8, v11, ... even if it is evil some plugin can be impacted by JDK at
> runtime).
> If it is per-project, [JVM and Command Line
> Options|https://maven.apache.org/docs/3.3.1/release-notes.html#JVM_and_Command_Line_Options]
> is not relevant and update {{JAVA_HOME}} each time in your environment could
> be boring.
> A command line user-custom-parameter (ex : {{-Dmy.jdk=11}}) could be simple
> to achieve that.
> A Maven script wrapper could be implemented for that, but it's like update
> the Maven distribution => evil.
> The *mavenrc_pre* (MNGSITE-246) could be perfect for that feature !
> But currently command line parameters are not used in script :(.
> If parameters are used dor script call, sample for {{mvn.cmd}} (windows):
> {code}
> if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd
> %*"
> {code}
> It's allow any user customization, using Maven standards.
> If relevant, I can provide PR.
> Best regards
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)