Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different repository in DistributionManagement and Repositories

Tags:

java

maven

nexus

In <DistributionManagement> ... </DistributionManagement> and <Repositories> ... <Repositories> sections, there can be a

<Repository> ... </Repository>

definition. What's the difference between the two definition? This is one example:

<distributionManagement>

                <downloadUrl>https://github.com/marytts/marytts/releases</downloadUrl>
                <repository>
                        <id>bintray</id>
                        <url>https://api.bintray.com/maven/marytts/marytts/marytts</url>
                </repository>
                <snapshotRepository>
                        <id>bintray</id>
                        <url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
                </snapshotRepository>
        </distributionManagement>

And

<repositories>
        <repository>
                <id>marytts-dependencies</id>
                <name>marytts-dependencies</name>
                <releases>
                        <enabled>true</enabled>
                </releases>
                <snapshots>
                        <enabled>false</enabled>
                </snapshots>
                <url>file://${project.local.repository.path}</url>
        </repository>
        <repository>
                <id>central</id>
                <name>jcenter</name>
                <releases>
                        <enabled>true</enabled>
                </releases>
                <snapshots>
                        <enabled>false</enabled>
                </snapshots>
                <url>http://jcenter.bintray.com</url>
        </repository>
</repositories>
like image 203
user697911 Avatar asked Sep 11 '15 04:09

user697911


People also ask

What are the types of repository?

There are exactly two types of repositories: local and remote: the local repository is a directory on the computer where Maven runs.

What is the use of distributionManagement in Maven?

In case of the project managed in Maven, package repository in which artifact is stored, should be specified using <distributionManagement> tag of pom. xml. The mvn deploy command uploads the artifact with HTTP PUT for the URL specified using <distributionManagement> tag.

What is repository and dependency?

Repository is a collection of artifacts (eg: jars). You can think of it as a mere storage / cache of various artifacts. Dependency is a situation where your project dependent on another artifact to perform its task (eg: compile, run, unit test)


1 Answers

Distribution Management

Distribution management acts precisely as it sounds: it manages the distribution of the artifact and supporting files generated throughout the build process. Starting with the last elements first:

Repository

Where as 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.

Deploy using the repository layout

To deploy your file using the maven layout you should define the distribution management location :

<project>
    ...
    <distributionManagement>
        <repository>
              <id>myrepository</id>
              <url>file:D:/repository/</url>
        </repository>
      </distributionManagement>
</project>       

Then you just need to execute the following command to get you artifact copied in your file system location

Maven command to deploy a file in the local file system

mvn deploy

Site Distribution

More than distribution to the repositories, distributionManagement is responsible for defining how to deploy the project's site and documentation.

In pom.xml, configure where to deploy your site within distributionManagement tag.

<distributionManagement>
    <site>
      <id>mkyongserver</id>
      <url>dav:http://127.0.0.1/sites/</url>
    </site>
</distributionManagement>

Relocation

Projects are not static; they are living things (or dying things, as the case may be). A common thing that happens as projects grow, is that they are forced to move to more suitable quarters. For example, when your next wildly successful open source project moves under the Apache umbrella, it would be good to give your users as heads-up that the project is being renamed to org.apache:my-project:1.0. Besides specifying the new address, it is also good form to provide a message explaining why.

Repositories

Repositories are collections of artifacts which adhere to the Maven repository directory layout. In order to be a Maven repository artifact, a POM file must live within the structure $BASE_REPO/groupId/artifactId/version/artifactId-version.pom. $BASE_REPO can be local (file structure) or remote (base URL); the remaining layout will be the same. Repositories exist as a place to collect and store artifacts. Whenever a project has a dependency upon an artifact, Maven will first attempt to use a local copy of the specified artifact. If that artifact does not exist in the local repository, it will then attempt to download from a remote repository. The repository elements within a POM specify those alternate repositories to search.

The repository is one of the most powerful features of the Maven community. The default central Maven repository lives on http://repo.maven.apache.org/maven2/. Another source for artifacts not yet in iBiblio is the Codehaus snapshots repo.

Be remember you can add only one <repository> and one <snapshotRepository> child inside <distributionManagement>

How to declare proxy

Just go to Maven-> conf-> setting.xml file and add proxy

<proxies>
    <proxy>
      <id>myproxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>global.proxy.mycompany.com</host>
      <port>8000</port>
      <username></username>
      <password></password>
      <nonProxyHosts>localhost,127.0.0.1</nonProxyHosts>
    </proxy>
 </proxies>
like image 91
Subodh Joshi Avatar answered Sep 30 '22 17:09

Subodh Joshi