简体   繁体   English

如何使用 Bitbucket 作为 maven 远程存储库?

[英]How to use Bitbucket as a maven remote repository?

We are planning to use bitbucket as source code repository as well remote repository for our maven based projects.我们计划使用 bitbucket 作为源代码存储库以及基于 maven 的项目的远程存储库。 I have created a repository on bitbucket something like below:我在 bitbucket 上创建了一个存储库,如下所示:

https://bitbucket.org/mycompany/maven-repository 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?如何使用特定于项目的 pom.xml 将我公司特定的项目 jar 推送到上述远程存储库中? Can you help me with a sample pom.xml?你能帮我提供一个示例 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.我们会将所有公司特定的 jar 推送到上述远程存储库中,以供公司内的其他项目作为 maven 依赖项使用。

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.上面是一个父 pom,它将被公司内的所有其他项目包含,我想将它推送到远程仓库以供其他公司特定项目使用。

When I run mvn deploy command, this is the error I get:当我运行mvn deploy命令时,这是我得到的错误:

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.谢谢你的帮助。

You can try http://synergian.github.io/wagon-git/index.html it has instructions for bitbucket.你可以试试http://synergian.github.io/wagon-git/index.html它有关于 bitbucket 的说明。

An alternative to using bitbucket is to use a dropbox folder for company.使用 bitbucket 的替代方法是使用公司的保管箱文件夹。 https://code.google.com/p/peter-lavalle/wiki/MavenOnDropBox Contains a very good step by step guide on how to do this. https://code.google.com/p/peter-lavalle/wiki/MavenOnDropBox包含有关如何执行此操作的非常好的分步指南。

Install jars in a local maven repository.在本地 Maven 存储库中安装 jar。

Make a directory eg maven-repo/repository创建一个目录,例如 maven-repo/repository

cd into maven-repo cd 到 maven-repo

execute the following (replacing the arguments by the ones that are relevant to your jar):执行以下操作(用与您的 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.将文件夹共享到 BitBucket 公共存储库。

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/ !!)在您的 pom.xml 中创建一个指向您的 bitbucket 文件夹的存储库。(您必须在路径https://bitbucket.org/your-user-or-group/your_maven-repo /raw/master/ 中使用 /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)来源: 在 Git 上托管第三方 jar 的 Maven 存储库(Bitbucket/Github)

How can I push my company specific project jars into the above remote repository using the project specific pom.xml?如何使用特定于项目的 pom.xml 将我公司特定的项目 jar 推送到上述远程存储库中?

You can't. 不能。 shouldn't in my opinion.在我看来不应该。

Bitbucket is not intended to be a maven repository . Bitbucket不打算成为Maven 存储库 Trying to get maven to deploy artifacts to BitBucket to it is just wrong may contravene Atlassian's terms of use.试图让 maven 将工件部署到 BitBucket 是错误的, 可能会违反 Atlassian 的使用条款。 On the other hand it might be fine.另一方面,它可能没问题。

You either need to should instead deploy to your own local repository or a public one. 需要 改为部署到您自己的本地存储库或公共存储库。

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.我遵循了这些说明,我可以将工件部署到 bitbucket,然后在另一个 maven 项目中使用它们。

The tweaks I had to make to get it working were:为了让它工作,我必须做的调整是:

  1. Upgrade Wagon-Git to v0.2.0将 Wagon-Git 升级到 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使用 git config --global user.email 配置 Git,因为它似乎没有选择我之前使用的 --local 设置

I also manually added a README.md to the repo but I don't think this was actually required.我还手动向 repo 添加了 README.md,但我认为这实际上不是必需的。

Once you have successfully deployed to the repo you should see all your files in the usual way via the BitBucket web front end.成功部署到存储库后,您应该可以通过 BitBucket Web 前端以通常的方式查看所有文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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