The Spring Boot Getting Started application includes build files for both Maven and Gradle. Given that the Oracle Developer Cloud Service also supports Gradle I thought this would be a good opportunity to demonstrate it in action.
I’m going to pick up where I left off in my previous entry, simply creating a new build that will use Gradle instead of Maven.
Step 1: Configure for Deployment to the Application Container Cloud Service (ACCS)
manifest.json
This file already exists and doesn’t need to change.
Deployment Archive
Just like with Maven, we need to instruct Gradle to package our application into a zip file for deployment to ACCS. With Gradle, this is achieved using the Zip plugin.
Edit build.gradle and add the following:
apply plugin: 'spring-boot' task zip(type: Zip) { from jar.outputs.files from( 'manifest.json' ) }
Step 2: Commit and Push the Changes
You know the drill.
Step 3: Create the Build
I could modify the existing Maven build, but instead I’m going to create a new build from the existing build.
Create a new Build Job by copying the Spring Boot GS. Name it something like Spring Boot GS (Gradle).
Switch to the Build Steps tab, delete the Invoke Maven 3 step and add a Gradle build step. Set the Tasks to build zip. Everything else can remain as is:
Switch to the Post Build tab select Archive the Artifacts. Change the Files to Archive to build/distributions/*.zip:
Save the configuration and click Build Now.
The build fails with the following:
> Connect to repo1.maven.org:443 [repo1.maven.org/151.101.68.209] failed: Connection timed out
The Gradle plug-in doesn’t (yet) pick up the proxy settings from the build engine so we need to provide this information to Gradle. The Developer Cloud Service exposes environment variables that include proxy information:
Using these variables we can dynamically create a gradle.properties file as follows (see Accessing the web via a proxy):
# # Generate a gradle.properties file for the DevCS environment running the build... # echo "systemProp.http.proxyHost="$HTTPS_PROXY_HOST >> gradle.properties echo "systemProp.http.proxyPort="$HTTP_PROXY_PORT >> gradle.properties echo "systemProp.http.nonProxyHosts="$NO_PROXY >> gradle.properties echo "systemProp.https.proxyHost="$HTTPS_PROXY_HOST >> gradle.properties echo "systemProp.https.proxyPort="$HTTPS_PROXY_PORT >> gradle.properties echo "systemProp.http.nonProxyHosts="$NO_PROXY >> gradle.properties
I’m going to add these commands to a shell script, create_gradle_properties.sh, which I will execute before I call the Gradle build.
Once the script is created and pushed to the repository, return to the Build Steps tab. Unfortunately, there’s not a way to insert a step before an existing step, so delete the Invoke Gradle build step and add an Execute shell step. Set the Command to sh create_gradle_properties.sh. Then add back the Invoke Gradle step as we did before:
Click Save and Build Now (if the Build Now button is disabled, click the Enable Build button).
Yikes, another failed build. It seems Gradle is configured to run an additional integration test which Maven was not. So wee also need to update the HelloControllerIT.java with our new greeting:
@Test public void getHello() throws Exception { ResponseEntity<String> response = template.getForEntity(base.toString(), String.class); assertThat(response.getBody(), equalTo("Greetings from Spring Boot running on ACCS!")); }
Commit and push to GitHub, which should trigger the build again (third time’s a charm, right?).
Dear Brian,
I am still getting an error in connecting to maven central repo (both https ans http) even after setting the proxy params for gradle using sh as you described. Any suggestions please?
Thanks in advance.
Regards,
Das
LikeLike
Solved (wrong directory); thanks.
LikeLike