简体   繁体   English

Maven / Spring私有存储库设置

[英]Maven/Spring private repository setup

Me and my team are pretty new to java side of things. 我和我的团队对java方面都很陌生。 We have created a new rest service that uses spring framework. 我们创建了一个使用spring框架的新休息服务。 We are trying to get the build automated. 我们正在尝试使构建自动化。

We have our own repo that we want to go to find dependencies. 我们有自己的回购,我们想去寻找依赖。 We put all third party dependencies in this repo and want the build to look into this repo while searching for dependencies. 我们将所有第三方依赖项放在此repo中,并希望构建在搜索依赖项时查看此repo。

Our pom.xml looks like this. 我们的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>

For these spring dependencies what are all the jars we need? 对于这些春天依赖,我们需要的所有罐子是什么? How do I find out which jars should we be having in our repo so that we can build our project? 我如何找到我们在回购中应该拥有哪些罐子,以便我们可以建立我们的项目?

You will need to specify the repository to use in your pom file. 您需要指定要在pom文件中使用的存储库。 As an example we use a Nexus repository where we put other jars needed. 作为一个例子,我们使用Nexus存储库,我们需要放置其他罐子。 It also acts as a cache against the Central repositories so we don't need to explicitly include all of the jars that come from there. 它还充当对中央存储库的缓存,因此我们不需要明确包含来自那里的所有jar。

You will need something like this in your pom.xml file: 你的pom.xml文件中需要这样的东西:

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

Then your build automation will need a way to specify the user and password. 然后,您的构建自动化将需要一种方法来指定用户和密码。 In a regular Maven setup you would use your user settings.xml file and populate it somewhat like this. 在常规的Maven设置中,您将使用您的用户settings.xml文件,并在此处填充它。 Different automated build systems may do it differently so you would need to see where yours gets it's Maven settings from. 不同的自动构建系统可能会以不同的方式执行,因此您需要查看您的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> 

In regard to determine the jar files to use the Maven Dependency Plugin is a good tool for analyzing a working build to see what is included. 关于确定要使用的jar文件Maven Dependency Plugin是一个很好的工具,用于分析工作构建以查看包含的内容。

Hopefully this helps but if not feel free to ask any questions. 希望这有帮助,但如果没有随意提出任何问题。

You can try something like this: 你可以尝试这样的事情:

<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>

This is part of the Apache Maven Dependency Plugin . 这是Apache Maven Dependency Plugin的一部分

If you also want to get the sources: 如果您还想获得来源:

<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>

And look into the alternateLocation folder. 并查看alternateLocation文件夹。 And of course you can change that folder to your preferenced location. 当然,您可以将该文件夹更改为您的首选位置。

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

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