30

We are planning to use bitbucket as source code repository as well remote repository for our maven based projects. I have created a repository on bitbucket something like below:

https://bitbucket.org/mycompany/maven-repository

How can I push my company specific project jars into the above remote repository using the project specific pom.xml? Can you help me with a sample pom.xml? We would be pushing all company specific jars into the above remote repository to be used by other projects within the company as maven dependencies.

Here is what I was trying so far to push one sample project into the remote repo:

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                  http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>corporate-pom</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<distributionManagement>
    <repository>
        <id>MyCompanyRepo</id>
        <url>https://bitbucket.org/mycompany/maven-repository</url>
    </repository>
</distributionManagement>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.7</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

The above is a parent pom, which will be included by all the other projects within the company and I wanted to push this to the remote repo to be used by other company specific projects.

When I run mvn deploy command, this is the error I get:

C:\Cooler\Work\dev\Projects\mycompany\wal-common>mvn deploy
[WARNING]
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'snapshotPolicy' (position: START_TAG seen ...</layo
ut>\n          <snapshotPolicy>... @203:27)  @ C:\Users\cooler\.m2\settings.xml,
line 203, column 27
[WARNING]
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building corporate-pom 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ corporate-pom
---
[INFO] Installing C:\Cooler\Work\dev\Projects\mycompany\wal-common\pom.xml to C:\
Users\cooler\.m2\repository\com\mycompany\corporate-pom\1.0\corporat
e-pom-1.0.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ corporate-pom ---
Uploading: https://bitbucket.org/mycompany/maven-repository/com/mycompany/corporate-   pom/1.0/corporate-pom-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.607s
[INFO] Finished at: Tue Sep 17 14:33:01 MST 2013
[INFO] Final Memory: 7M/122M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:
deploy (default-deploy) on project corporate-pom: Failed to deploy artifacts: Co
uld not transfer artifact com.mycompany:corporate-pom:pom:1.0 from/
to CompanyREPO (https://bitbucket.org/mycompany/maven-repository): Connection to h
ttp://:8080 refused: Connection refused: connect -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
xception 

Thanks for your help.

cooler
  • 753
  • 4
  • 9
  • 18

4 Answers4

15

You can try http://synergian.github.io/wagon-git/index.html it has instructions for bitbucket.

An alternative to using bitbucket is to use a dropbox folder for company. https://code.google.com/p/peter-lavalle/wiki/MavenOnDropBox Contains a very good step by step guide on how to do this.

ams
  • 60,316
  • 68
  • 200
  • 288
11

Install jars in a local maven repository.

Make a directory e.g. maven-repo/repository

cd into maven-repo

execute the following (replacing the arguments by the ones that are relevant to your jar):

mvn install:install-file -DgroupId=com.rapid_i -DartifactId=rapidminer -Dversion=5.3.006 -Dfile=/path/to/artifact/rapidminer.jar -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=./repository  -DcreateChecksum=true

Share the folder to a BitBucket public repository.

Create a repository in your pom.xml pointing to you bitbucket folder.(you must use /raw/master in the path https://bitbucket.org/your-user-or-group/your_maven-repo/raw/master/ !!)

<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.activeintel</groupId>
<artifactId>rapidminer-proj</artifactId>
<version>0.0.1</version> 

<!-- Dependency to jar on Maven Repository on Git-BitBucket -->
<dependencies>
    <dependency>
        <groupId>com.rapid_i</groupId>
        <artifactId>rapidminer</artifactId>
        <version>5.3.006</version>
    </dependency>
</dependencies>

<!-- Maven Repository on Git-BitBucket -->
<repositories>
<repository>
    <id>neil_rubens-repository</id>
    <url>https://bitbucket.org/your-user-or-group/your_maven-repo/raw/master/repository/</url>
</repository>
</repositories>

</project>

Source: Hosting Maven Repository for third-party jars on Git (Bitbucket/Github)

delkant
  • 2,304
  • 1
  • 29
  • 28
  • Note that [link-only answers](http://meta.stackoverflow.com/tags/link-only-answers/info) are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference. – kleopatra Mar 28 '14 at 14:45
  • i think this might be the best of the best, also madam @kleopatra i think the top answer above needs your attention with that comment.. :) – Elltz Oct 21 '15 at 22:45
2

How can I push my company specific project jars into the above remote repository using the project specific pom.xml?

You can't. shouldn't in my opinion.

Bitbucket is not intended to be a maven repository. Trying to get maven to deploy artifacts to BitBucket to it is just wrong may contravene Atlassian's terms of use. On the other hand it might be fine.

You either need to should instead deploy to your own local repository or a public one.

mounds
  • 1,303
  • 12
  • 11
  • 3
    I think this is incorrect. People clearly have done this [(like this guy)](http://blog.chrissom.com/dev/bitbucket-as-a-maven-repository.html) and as ams says, wagon-git aims to do just this. – BigMikeW Oct 16 '13 at 00:56
  • Thanks @BigMikeW, I was not aware of wrapper plugins like wagon-git doing this - an interesting concept. I'll update my answer in light of this. I do wonder though how Atlassian would classify this kind of use under its terms of use policy - specifically [section 3.5](https://www.atlassian.com/end-user-agreement?utm_source=bitbucket&utm_medium=link&utm_campaign=footer). I wouldn't do it, but hey if it works, it works. – mounds Oct 16 '13 at 04:59
  • 2
    they seem to be meaning no multimedia file hosting in that section. I know there are instructions on how to host static web sites from Bitbucket and also if you look at [this defect](https://bitbucket.org/site/master/issue/7101/bug-accessing-private-reposotory-with) they don't take issue with it in the comments. – BigMikeW Oct 16 '13 at 21:18
  • wagon-git is a general purpose git wagon, not just for Bitbucket or Github. Anyway, I'm adding some disclaimer notes. Thanks. – Martín Schonaker Jan 15 '14 at 18:33
  • @mounds Do you think I can reference a [Maven repository hosted in Stash](http://stackoverflow.com/questions/38747160/how-to-use-stash-as-a-maven-remote-repository-for-a-gradle-project) from Gradle? – JJD Aug 03 '16 at 16:13
  • I don't see why not - as @mschonaker says above, git wagon is a general purpose solution so it should work with any git repo. – mounds Aug 04 '16 at 01:24
1

I've now managed to get this working. I followed these instructions and I can deploy artifacts to bitbucket and then use those in another maven project.

The tweaks I had to make to get it working were:

  1. Upgrade Wagon-Git to v0.2.0
  2. Configure Git using git config --global user.email as it didn't seem to be picking up the --local setting I had used previously

I also manually added a README.md to the repo but I don't think this was actually required.

Once you have successfully deployed to the repo you should see all your files in the usual way via the BitBucket web front end.

JJD
  • 50,076
  • 60
  • 203
  • 339
BigMikeW
  • 821
  • 5
  • 14
  • 8
    Your 'these instructions' link is dead! :( – Abby Jan 13 '14 at 17:02
  • You're right @Abby. Sorry I didn't make a copy of them! – BigMikeW Jun 18 '15 at 23:21
  • I am trying to setup an internal repository with [Stash (now named Bitbucket Server)](https://www.atlassian.com/software/bitbucket/server). Did anyone do this successfully? – JJD Aug 03 '16 at 14:27