Location of Maven Home on Cloud Foundry - maven

I have an application that programmatically runs Maven command "clean package" at runtime, using plugin maven-invoker.
To be able to run this application on Cloud Foundry, we need to set Maven Home on the invoker.
This question is similar to Maven Invoker: IllegalStateException, except that we are deploying on Cloud Foundry but don't know how to get the value for Maven Home.
Is it possible to get it from CF environment?

The Java build pack does not install Maven or set any Maven related environment variables. You can however set whatever environment variables that you like via cf set-env or in the env block of your manifest.yml file.
https://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html#env-block
Your app when running on CF will run as the vcap user and it runs out of /home/vcap/app (or reference $HOME env variable). If you need to pick a location to use for Maven home, I would suggest putting it under that directory.

Related

Running Spring Boot Application.main() via IntelliJ doesn't find my local profile

I've been running my Spring Boot (2.1.0) app via Gradle bootRun but since adding in the Actuator, this causes the app to not actually shutdown when I tell IntelliJ to stop the app. For whatever reason, this is only an issue when running in Debug mode.
The solution I found online was to just run the Application.main() but now, my local profile isn't being picked up. So I have the typical application.yml along with various other profiles. All of the developers have an application-local.yml that is sitting at the root of the project and is ignored by git. Running Gradle's bootRun with local as the active profile works. But running Application.main() with the local active profile does not pick up the application-local.yml file's config.
As you can see in the image, I've not only specified the profile in Intellij's Active profiles section, but also as a VM option just like I do when running via Gradle.
One more thing which you can try
Set spring.profiles.active=local in Environment Variables below VM Options

Accessing Properties From Gradle in Groovy

I'm trying to set a variable/property within Gradle during a war build for deployment. However, when I try setting it, it seems it just gets set to null whenever I try accessing it from groovy. I'm building on a local machine with the command (I've tried both):
gradle build -Dgrails.env=development -Dtest.variable=/app/testing/development or gradle war -Dgrails.env=development -Dtest.variable=/app/testing/development
Then I deploy the WAR file to a Tomcat server.
But when I try accessing that variable by System.getProperty("test.variable") I am receiving a null error on that property. What do I need to do to set a command-line variable in Gradle and have it be accessible in Groovy when I try to deploy the WAR file on a server? I know the grails.env is working as it is reading the proper values in the application.yml file, but I cannot access the given property that I am trying to set.

tomcat7-maven-plugin to deploy spring boot with appropriate spring profile selected

My goal is to be able to use the tomcat-maven plugin to deploy my spring boot application from the command line where an argument is supplied that tells spring which profile to use like this:
mvn tomcat7:deploy -Dspring.profiles.active="dev"
I've tried several different things such as the solution described here but the default application.properties is still always selected.
The only way that I've been able to get the application-dev.properties selected is by using
mvn spring-boot:run -Dspring.profiles.active="dev"
But we don't want to have tomcat packaged in our war
I'm new to maven and spring boot and I've been spinning my wheels for the better part of a a day now so any advice would be appreciated.
Consider using MAVEN_OPTS environment variable to set VM argument. (Linux/osx) example you would need to execute before your maven goal:
export MAVEN_OPTS="-Dspring.profiles.active=dev"
I found out the issue and I was able to get the correct profile selected using
export SPRING_PROFILES_ACTIVE=dev. The problem that I was having was when I was starting my local tomcat server through the eclipse UI my environment variables were being ignored. When starting tomcat through startup.bat the environment variable gets used and spring uses the correct profile.

How do I set up Spring and Maven environment for working offline?

I need to set up Spring and Maven for working offline. I am working with Spring Tool Suite.What environment variables do I need to configure besides M2 env var? When I try to add dependencies in pom.xml, and type springframework, nothing comes up in the search bar. I get "Core exception Could not calculate build plan Plugin org.apache.maven.plugins:m. I understand STS uses web services to locate the jars, so how do I configure Spring and Maven to work offline? Thank you.
Maven uses central repositoty to update dependencies via internet if you want run it offline you need to configure you local repository.See Setting local Maven repository
This is something that you will find very difficult or near impossible unless you somehow get all the relevant jars from spring and place them in your .m2 repo directory.
Your question has been asked a number of times on here ...
Have a look through these 2 questions which I assume is exactly what you have encountered.
Question 1
Question 2
Also one last note ...
After you setup your variables did you restart your PC I know sometimes I forget to do this when updating environment variables.
Before you go offline run the following:
mvn dependency:go-offline
That will download all your dependencies and plugins that you need to build your project into ~/.m2/repository.
Once you've run that you can now build your project offline using the '-o' flag:
mvn install -o
It's also possible to configure the offline mode globally by setting the offline property in the ~/.m2/settings.xml file:
true

Setting environment variables in Gradle

I am using the tomcat plugin to start Tomcat server using a war file i have built using the war plugin.
Before the app starts i need to set some environment variables.
Is there a way to do that?
From what I can see in the Gradle Tomcat plugin docs, the plugin runs Tomcat in the Gradle process. Environment variables for that process can only be set from outside Gradle, in a manner appropriate for your environment/OS. Alternatively, you might want to look into the Gradle Cargo and Gradle Arquillian plugins, which can also run containers in an external process.
PS: Please don't double-post here and on http://forums.gradle.org.

Resources