繁体   English   中英

Maven / Spring私有存储库设置

[英]Maven/Spring private repository setup

我和我的团队对java方面都很陌生。 我们创建了一个使用spring框架的新休息服务。 我们正在尝试使构建自动化。

我们有自己的回购,我们想去寻找依赖。 我们将所有第三方依赖项放在此repo中,并希望构建在搜索依赖项时查看此repo。

我们的pom.xml看起来像这样。

   <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>com.squareup.retrofit</groupId>
        <artifactId>retrofit</artifactId>
        <version>1.9.0</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>       

</dependencies>

对于这些春天依赖,我们需要的所有罐子是什么? 我如何找到我们在回购中应该拥有哪些罐子,以便我们可以建立我们的项目?

您需要指定要在pom文件中使用的存储库。 作为一个例子,我们使用Nexus存储库,我们需要放置其他罐子。 它还充当对中央存储库的缓存,因此我们不需要明确包含来自那里的所有jar。

你的pom.xml文件中需要这样的东西:

<!-- location for other artifact uploads -->
<repositories>
    <repository>
        <id>YourRepositoryId</id>
        <url>http://yourrepo.com/nexus/content/repositories/thirdparty/</url>
    </repository>
</repositories>

然后,您的构建自动化将需要一种方法来指定用户和密码。 在常规的Maven设置中,您将使用您的用户settings.xml文件,并在此处填充它。 不同的自动构建系统可能会以不同的方式执行,因此您需要查看您的Maven设置从何处获取。

 <!-- This exists so that environments without a user can still access the repository. -->
<settings>
<servers>
    <server>
        <id>YourRepositoryId</id>
        <username>yourUserName</username>
        <password>yourPassword</password>
    </server>
</servers>
</settings> 

关于确定要使用的jar文件Maven Dependency Plugin是一个很好的工具,用于分析工作构建以查看包含的内容。

希望这有帮助,但如果没有随意提出任何问题。

你可以尝试这样的事情:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>${maven-dependency-plugin.version}</version>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
        </execution>
    </executions>
</plugin>

这是Apache Maven Dependency Plugin的一部分

如果您还想获得来源:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>${maven-dependency-plugin.version}</version>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
        </execution>
        <execution>
            <id>sources</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <classifier>sources</classifier>
                <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
        </execution>
    </executions>
</plugin>

并查看alternateLocation文件夹。 当然,您可以将该文件夹更改为您的首选位置。

暂无
暂无

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

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