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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18859138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:59:12  来源:igfitidea点击:

How to use Bitbucket as a maven remote repository?

gitmavenbitbucket

提问by cooler

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:

我们计划使用 bitbucket 作为源代码存储库以及基于 maven 的项目的远程存储库。我在 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? 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.

如何使用特定于项目的 pom.xml 将我公司特定的项目 jar 推送到上述远程存储库中?你能帮我提供一个示例 pom.xml 吗?我们会将所有公司特定的 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 deploycommand, 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.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.

谢谢你的帮助。

回答by ams

You can try http://synergian.github.io/wagon-git/index.htmlit 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. https://code.google.com/p/peter-lavalle/wiki/MavenOnDropBoxContains a very good step by step guide on how to do this.

使用 bitbucket 的替代方法是使用公司的保管箱文件夹。 https://code.google.com/p/peter-lavalle/wiki/MavenOnDropBox包含有关如何执行此操作的非常好的分步指南。

回答by delkant

Install jars in a local maven repository.

在本地 Maven 存储库中安装 jar。

Make a directory e.g. 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)

回答by BigMikeW

I've now managed to get this working. I followed these instructionsand 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
  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
  1. 将 Wagon-Git 升级到 v0.2.0
  2. 使用 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 前端以通常的方式查看所有文件。

回答by mounds

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.

不能。在我看来不应该。

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

Bitbucket不打算成为Maven 存储库。试图让 maven 将工件部署到 BitBucket是错误的,可能会违反 Atlassian 的使用条款。另一方面,它可能没问题。

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

需要改为部署到您自己的本地存储库或公共存储库。