How to Pass Jvm Options from Bootrun

How to pass JVM options from bootRun

Original Answer (using Gradle 1.12 and Spring Boot 1.0.x):

The bootRun task of the Spring Boot gradle plugin extends the gradle JavaExec task. See this.

That means that you can configure the plugin to use the proxy by adding:

bootRun {
jvmArgs = "-Dhttp.proxyHost=xxxxxx", "-Dhttp.proxyPort=xxxxxx"
}

to your build file.

Of course you could use the systemProperties instead of jvmArgs

If you want to conditionally add jvmArgs from the command line you can do the following:

bootRun {
if ( project.hasProperty('jvmArgs') ) {
jvmArgs project.jvmArgs.split('\\s+')
}
}

gradle bootRun -PjvmArgs="-Dwhatever1=value1 -Dwhatever2=value2"

Updated Answer:

After trying out my solution above using Spring Boot 1.2.6.RELEASE and Gradle 2.7 I observed that it was not working as some of the comments mention.
However, a few minor tweaks can be made to recover the working state.

The new code is:

bootRun {
jvmArgs = ["-Dhttp.proxyHost=xxxxxx", "-Dhttp.proxyPort=xxxxxx"]
}

for hard-coded arguments, and

bootRun {
if ( project.hasProperty('jvmArgs') ) {
jvmArgs = (project.jvmArgs.split("\\s+") as List)

}
}

for arguments provided from the command line

Passing JVM args to SpringBoot bootRun Gradle task

Got it working by using jvmArgs, as detailed in this SO question [ How to pass JVM options from bootRun ]

bootRun {
jvmArgs = ["-Xbootclasspath/p:<fully-qualified-path-to-jar>"]
}

Passing JVM args from build.gradle in Spring Boot 2.0.3

You can set these values in application.property /yml file and use that property key in @value annotation.

application-prod.properties

configFolder="somefolder/path"

These property files can be set/modified in runtime.

You can take a look at this (5.1) section: https://www.baeldung.com/properties-with-spring
Is that fine for you?? If not please let me know.

How to add JVM options to program started by mvn spring-boot:run

You can configure spring-boot-maven-plugin to always include you jvm options when run:

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Dapp.name=test
</jvmArguments>
</configuration>
</plugin>

Or if you don't need that arguments to stay permanently, use this on the command line:

mvn spring-boot:run -Drun.jvmArguments="..."

Check documentation for details.

How to pass --illegal-access JVM argument to spring boot maven plugin

If you're trying to run the application in IntelliJ, you don't need to pass anything into Maven. In IntelliJ, open the run configuration for your app and under Environment->VM options add --illegal-access=permit. See the attached image, Main class would be your fully qualified location of your @SpringBootApplication class, e.g. com.something.MySpringBootApplication

Sample Image

When you start your app in debug mode in IntelliJ, you'll see something like

/Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:52737,suspend=y,server=n --illegal-access=permit -XX:TieredStopAtLevel=1..., notice the argument getting passed to your app.



Related Topics



Leave a reply



Submit