简体   繁体   中英

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

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.

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 addtag just after thetag.

<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 sameinto 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? .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM