DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Part 2 - How to Hive on GCP using Google DataProc and Cloud Storage
  • How to Hive on GCP Using Google DataProc and Cloud Storage: Part 1
  • Upload Files to Google Cloud Storage with Python
  • Simplify Your Compliance With Google Cloud Assured Workloads

Trending

  • Reducing Hallucinations Using Prompt Engineering and RAG
  • Continuous Quality Engineering: The Convergence of CI/CD, Chaos Testing, and AI-Powered Test Orchestration
  • Run Scalable Python Workloads With Modal
  • Why API-First Frontends Make Better Apps
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Host Your Maven Artifacts Using Google Cloud Storage

Host Your Maven Artifacts Using Google Cloud Storage

If your team uses Java and Google Cloud, it might be convenient to explore using Google Cloud for your Maven artifacts.

By 
Emmanouil Gkatziouras user avatar
Emmanouil Gkatziouras
DZone Core CORE ·
Jun. 08, 18 · Opinion
Likes (6)
Comment
Save
Tweet
Share
13.4K Views

Join the DZone community and get the full member experience.

Join For Free

If you use Google Cloud and you use Java for your projects, then Google Cloud Storage is a great place to host your team's artifacts.

It is easy to set up and pretty cheap. It is also much simpler than setting up one of the existing repository options (JFrog, Nexus, or Archiva, for example) if you are not particularly interested in their features.

To get started you need to specify a Maven wagon which supports Google Cloud Storage. We will use the Google Storage wagon.

Let’s get started by creating a Maven project:

mvn archetype:generate -DgroupId=com.test.apps -DartifactId=GoogleWagonTest -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false


We are going to add a simple service.

package com.test.apps;

public class HelloService {

    public String sayHello() {

        return "Hello";
    }
}

Then we are going to add the Maven wagon which will upload and fetch our binaries to the Google Cloud Storage.

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

Then we shall create the Google Cloud Storage bucket which will host our artifacts.

Image title


Our bucket will be called "mavenrepository."

Now that we have set up our bucket in Google we shall set the distribution management on our Maven project.

<distributionManagement>
    <snapshotRepository>
        <id>my-repo-bucket-snapshot</id>
        <url>gs://mavenrepository/snapshot</url>
    </snapshotRepository>
    <repository>
        <id>my-repo-bucket-release</id>
        <url>gs://mavenrepository/release</url>
    </repository>
</distributionManagement>


From the Maven documentation:

"Whereas the repositories element specifies in the POM the location and manner in which Maven may download remote artifacts for use by the current project, distributionManagement specifies where (and how) this project will get to a remote repository when it is deployed. The repository elements will be used for snapshot distribution if the snapshotRepository is not defined."

The next step is the most crucial and this has to to do with authenticating to Google Cloud.

You need to have the gcloud command line setup in your system and you must issue a login
‘gcloud auth login –brief’ with an account that has access to the bucket we created previously.
The other way is to use the GOOGLE_APPLICATION_CREDENTIALS  environmental variable. You can use this GOOGLE_APPLICATION_CREDENTIALS  in order to set the path to your Google application credentials file. The credentials file should also be able to access the bucket we created previously.

And now the easiest part, which is deploying:

mvn deploy


Now since your artifact has been deployed you can use it in another repo by specifying your repository and your wagon.

<repositories>
    <repository>
        <id>my-repo-bucket-snapshot</id>
        <url>gs://mavenrepository/snapshot</url>
    </repository>
    <repository>
        <id>my-repo-bucket-release</id>
        <url>gs://mavenrepository/release</url>
    </repository>
</repositories>

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

That’s it! Next thing you know, your artifact will be downloaded by Maven through Google Cloud Storage and used as a dependency in your new project.

Google Cloud Storage Cloud storage Google (verb) Cloud Apache Maven Artifact (UML) Host (Unix)

Published at DZone with permission of Emmanouil Gkatziouras, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Part 2 - How to Hive on GCP using Google DataProc and Cloud Storage
  • How to Hive on GCP Using Google DataProc and Cloud Storage: Part 1
  • Upload Files to Google Cloud Storage with Python
  • Simplify Your Compliance With Google Cloud Assured Workloads

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: