Manage Binaries and Dependencies Using the Project’s Maven Repository

When a project is created, Oracle Developer Cloud Service (DevCS) creates a hosted Maven repository in the project, which is also called as the project Maven repository. You can use the repository to store binary files and dependencies. If you’re developing Maven applications, you can use the Maven repository to store and access build artifacts.

If you see the No Storage Configured error message, contact the Organization Administrator (a user with the Developer Service Administrator identity domain role) to enable the storage configuration of the organization. If you’re the Organization Administrator, configure the storage configuration of the organization. See Connect to OCI or OCI Classic.

Maven Concepts and Terms

Apache Maven is a software project management tool that uses the Project Object Model (POM) concept to manage a project's build.

If you’re new to Maven, see https://maven.apache.org to learn about Maven basics such as POM files and Maven repositories.

In DevCS, you use the project’s Maven repository to store build artifacts and dependencies for your project’s applications. Usually, you store the dependencies on the project’s Maven repository that aren’t available on a public Maven repository, such as Maven Central Repository or Oracle Maven Repository.

Here are the terms that this documentation uses to describe the Maven terms and components of a project.

Term Description

POM file

An XML file that contains configuration about how to build the application. Usually, the file is saved as pom.xml. For more information, see https://maven.apache.org/guides/introduction/introduction-to-the-pom.html.

Browse view

Displays and allows you to browse artifacts of the project’s Maven repository.

Upload view

Allows you to upload artifacts manually to the project’s Maven repository.

Artifact Search view

Enables you to search artifacts in the project’s Maven repository.

To upload and access the files of the repository programmatically, configure the POM file of your application. You can use the project Maven repository among other projects of the organization for local builds as well as project builds.

Upload an Artifact Manually

From the Upload view, you can upload artifacts manually to the project’s Maven repository without installing Maven on your computer. You must be a project owner or member to upload an artifact to the project Maven repository.

  1. In the navigation bar, click Maven Maven.
  2. On the right side of the page, click Upload.
  3. In the Upload Artifacts section, use the drag-and-drop operation to drop files to the drop area, or click the select artifact files link, browse, and select the files.
  4. In the table below the Upload Artifacts section, if necessary, update the Classifier field of the selected artifact.

    If you’re uploading only one artifact, you can leave the classifier field empty. If you’re uploading multiple artifacts, provide the classifier value for each artifact. The classifier helps to distinguish artifacts that were built from the same POM file but differ in their content. The classifier string is appended to the artifact name, after the version number.

    For example, if you’re uploading artifacts with identical names but different extensions (such as fileX-1.0.jar and fileX-1.0.pdf), you may provide classifiers, such as main and documentation for these files. After the files are uploaded, they are renamed to fileX-1.0-main.jar and fileX-1.0-documentation.pdf.

  5. After you add the artifacts, you must specify their Maven coordinates manually or from a POM file. These coordinates are used when uploading artifacts to the project’s Maven repository.

    If you want to specify the artifacts’ Maven coordinates manually, note the following:

    • The auto-suggest list of GroupId, Version, and ArtifactId are based on Maven indexes. If no index data is available, the auto-suggest list isn’t displayed.

    • By default, the Generate POM check box is selected. The upload process deploys the artifact and generates the default POM file, maven-metadata.xml, and associated sha1/md5 checksum files. If maven-metadata.xml already exists, it’s updated.

      If you deselect the check box, the upload process deploys the artifact to the target deployment path based on Maven attributes. The POM file and the maven-metadata.xml file aren’t generated.

  6. Click Start Upload.

    You can track the transfer status and its progress in the drop area of the Upload Artifacts section. To cancel the upload process, click Cancel Upload. The upload process will also be cancelled if the page is refreshed or closed.

Upload Artifacts Using the Maven Command-Line Interface

You can also use the Maven command-line interface to upload artifacts to the project’s Maven repository.

The Maven repository URL is available on the Project Home page of your project. Use the dav: URL to upload files and the http:// URL to view them in the browser.

Note that the credentials in settings.xml aren’t required to access the project Maven repository when running a build. The build job has full access to the project Maven repository for uploads and downloads.

  1. Download and install Maven on your local computer.
    You can download Maven from http://maven.apache.org/download.cgi.
  2. Open MVN_HOME/conf/settings.xml in a text editor and make the following changes.
    1. Specify the proxy server, if necessary.
      Example:
      <proxies>
      	<proxy>
      		<active>true</active>
      		<protocol>http</protocol>
      		<host>PROXY_URL</host>
       		<port>80</port>
       		<nonProxyHosts>www.anything.com|*.somewhere.com</nonProxyHosts>
       	</proxy>
      </proxies>
    2. Specify a unique ID and your DevCS user name and password to access the project Maven repository.
      Example:
      <servers>
      	<server>
      		<id>remoteRepository</id>
      		<username>USERNAME</username>
      		<password>PASSWORD_IN_PLAINTEXT</password>
      	</server>	
      </servers>
    3. Specify a unique ID, name, and URL for the project Maven repository. You can copy the Maven repository URL from the Repositories tab of the Project Home page.
      Example:
      <profiles>
      	<profile>
      		<id>default</id>
      		<repositories>
      			<repository>
      				<id>remoteRepository</id>
      				<name>My Remote Repository</name>
      				<url>dav:https://developer.us2.oraclecloud.com/……/maven/</url>
      				<layout>default</layout>
      			</repository>
      		</repositories>
      	</profile>
      </profiles>
  3. Open the command-line and follow these commands to upload files to the hosted Maven repository. Ensure that the MVN_HOME/bin path is available in the PATH variable.
    1. Navigate to the directory that contains the files that you want to upload.
    2. Create the pom.xml file, if it hasn’t been created already.
      For more information about pom.xml, see http://maven.apache.org/guides/introduction/introduction-to-the-pom.html.
    3. Run the mvn deploy command to upload files.
      Example: mvn deploy:deploy-file -DpomFile=c:\myproject\pom.xml -Dfile=c:\myproject\myfile.jar -DrepositoryId=remoteRepository -X -Durl=dav:https://developer.us2.oraclecloud.com/……/maven/

Search Artifacts

To search for artifacts, use the Artifact Search view.

You can specify the following search criterion:
  • GroupID

  • ArtifactID

  • Version

  • Classifier

  • Size and updated date (available in Show Advanced Options)

The search result is grouped by Maven coordinates in the Artifacts (default) tab and by files in the Files tab.

Download an Artifact Manually

You can download an artifact manually from the Browse view of the Maven page.

  1. In the navigation bar, click Maven Maven.
  2. If necessary, on the right side of the page, click Browse.
  3. Browse and select the artifact that you want to download.
    You can also click Artifact Search to search for the artifact and then click its name to open it in the Browse view.
  4. With the artifact selected, in Artifact Details on the right, click Download Download.
The browser downloads the artifact and saves it to your computer.

Copy Distribution Management Snippets

To upload or download dependencies while running a build, add the dependency management snippet or the dependency declaration snippet to the POM file.

Action How To

Copy the Dependency Management snippet

  1. In the Browse view, navigate to the root directory.

  2. In the Artifact Details section, expand Distribution Management.

  3. In the Maven tab, click Copy Copy to clipboard to copy the <distributionManagement> code snippet to the clipboard.

  4. Open the pom.xml file of your project in a code editor (or a text editor) and paste the contents of the clipboard under the <project> element.

Copy the Dependency Declaration snippet

  1. Browse the Maven repository and select the artifact.

    You may also click Artifact Search to search for the artifact and then click its name to open it in the Browse view.

  2. In the Artifact Details section, expand Dependency Declaration.

  3. In the Maven tab, click Copy Copy to clipboard to copy the <dependency> code snippet to the clipboard.

  4. Open the pom.xml file of your project in a code editor (or a text editor) and paste the contents of the clipboard under the <dependencies> element.

Tip:

You can copy the Maven repository’s URL from the distribution snippet. You can also copy the URL from the Project Home page.

On the Project Home page, click the Repositories tab. In the Maven section, from the Clone menu of Project Repository, select HTTP or Webdav, and click Copy Copy to clipboard to copy the URL to clipboard.

Use the HTTP URL to connect to the Maven repository using the HTTP protocol. Use the Webdav URL to connect to the repository using the Webdav protocol.

Maven Repository Administration

You can configure the Maven repository to limit the number of snapshots and overwrite an artifact if another with same groupID, artifactID, and version value is uploaded.

Configure Auto-Cleanup of Snapshots

By default, when you upload a new snapshot of an artifact to the project’s Maven repository manually or through job builds, the repository retains the old versions of the snapshots. You can configure the project to remove the old versions when a new version is uploaded.

the project owner icon You must be assigned the project Owner role to configure the auto-cleanup.
  1. In the navigation bar, click Project Administration Gear.
  2. Click Repositories.
  3. In Maven Repository, if necessary, expand Configure auto cleanup for Snapshot versions.
  4. Select the Purge check box.
  5. In Default Max Snapshots, enter a number between 2 and 500 to specify the maximum versions to retain. By default, 2 versions of the snapshots are retained.

All changes are saved automatically when you navigate to another field. After the rule is enabled, any new upload of a snapshot will remove its older versions if the number of snapshots exceed the value in Default Max Snapshots.

You can also add exceptions to the auto-cleanup and Default Max Snapshots rule and customize the snapshot counts. The project Maven repository retains the snapshot counts of group IDs and artifacts defined in the Customized Snapshot Counts section and uses the default value specified in Default Max Snapshots for artifacts that don’t have exceptions defined.

To define exceptions and customize snapshot count:

  1. In the Maven Repository section of the Repositories page, select the Purge check box and configure the default auto-cleanup as described above.

  2. To add an artifact group or an artifact name as an exception, click + Add in the Customized Snapshot Counts section.

  3. Specify these details:

    • Group Id (Required): Enter or select the Group ID of the artifact. You can select the ID from the list or start typing and then select the ID from the list of suggestions. The auto-suggest list is based on the Maven indexes. If no index data is available, the auto-suggest list doesn’t display.

    • Artifact Id (Optional): Enter or select the Artifact ID of the artifact. You can select the ID from the list or start typing and then select the ID from the list of suggestions. The auto-suggest list is based on the Maven indexes. If no index data is available, the auto-suggest list doesn’t display.

    • Snapshot Count: Select the number of snapshots to retain in the project Maven repository. By default, 2 snapshots are retained.

To remove an exception, on the right, click Remove the Remove icon. For a long list of exceptions, you can use the Filter field and enter a search coordinates criteria to see the exceptions matching the criteria. If you enter an exception with duplicate coordinates, an error message Unable to save. Coordinates already exists. Enter unique coordinates appears.

Configure Overwrite for Artifacts

By default, when a user tries to upload a Maven release artifact with the same groupID, artifactID, and version values of an existing artifact to the project’s Maven repository, the upload fails. If a build tries to upload an artifact with duplicate groupID, artifactID, and version values, it fails too. To allow the duplicate artifact to be uploaded, you can configure the project’s Maven repository to allow the build to upload artifacts with duplicate groupID, artifactID, and version values.

the project owner icon You must be assigned the project Owner role to configure the overwrite property.
  1. In the navigation bar, click Project Administration Gear.
  2. Click Repositories.
  3. In Maven Repository, if necessary, expand Configure Overwrite Property for Release Artifacts.
  4. Select the Allow check box.