How to deploy/host the maven artifact of a java project to Google Cloud Storage?

Peter Williams :

We have a Spring based multiple project. We are deploying our spring boot application into Google Cloud Platform. We have a requirement to build a maven artifact so that we can use the artifact into multiple spring based project.

Altaf Java :

For this, you can use google-storage-wagon maven dependency. This is really great article How to deploy/host the maven artifact of a project to Google Cloud Storage?. If you will follow some steps then definitely you will achieve your goal.

Step 1: Create a project for which you want to build the maven artifact. mvn archetype:generate -DgroupId=com.javaaltaf -DartifactId=SMSGateway -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Step 2: Now create a simple class for testing purpose. By the way, based on your requirement you can create multiple classes.

public class MessageSender {
 public String sendSMS(String mobile, String message) {
  return "SMS sending....to " + mobile + "  with messsage=" + message;
 }
}

Step 3: You will have to add an extension inside tag in your pom.xml provided by Emmanouil Gkatziouras. You can download the latest google-storage-wagon from here. This will upload and download our artifact to/from Google Cloud Storage.

<build>
  <extensions>
   <extension>
    <groupId>com.gkatzioura.maven.cloud</groupId>
    <artifactId>google-storage-wagon</artifactId>
    <version>1.6</version>
   </extension>
  </extensions>
</build>

Step 4: Now create a Bucket by going Menu->Storage->Browser. After that goto the overview section and copy the gsutil URL. Now set up the bucket information into pom.xml so that maven can understand the destination of the artifact. For this you will have to add tag just after the tag.

<distributionManagement>
  <snapshotRepository>
   <id>mysms-snapshot</id>
   <url>gs://altafsms/snapshot</url>
  </snapshotRepository>
  <repository>
   <id>mysms-release</id>
   <url>gs://altafsms/release</url>
  </repository>
 </distributionManagement>

Step 5: You should have installed the Google Cloud SDK. If not then you need to install. After installing you nee to login into GCS. You can use the command gcloud auth application-default login

Step 6: Finally use the command mvn deploy to deploy your maven artifact into google cloud storage.

Step 7: You will have to add the same into your pom.xml which you already added in the previous project.

<build>
<extensions>
 <extension>
  <groupId>com.gkatzioura.maven.cloud</groupId>
  <artifactId>google-storage-wagon</artifactId>
  <version>1.6</version>
 </extension>
</extensions>
</build>

After that add the GAV(groupId, artifact id, version) of the earlier project as tag in your pom.xml file and you have done. For the complete information, you can read this blog How to deploy/host the maven artifact of a project to Google Cloud Storage?.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=415814&siteId=1