Spring boot 使用Maven将springboot可执行文件部署到Nexus
我正在使用Maven构建我的可执行SpringBoot,我还使用SpringBootMaven插件Spring boot 使用Maven将springboot可执行文件部署到Nexus,spring-boot,maven,deployment,nexus,Spring Boot,Maven,Deployment,Nexus,我正在使用Maven构建我的可执行SpringBoot,我还使用SpringBootMaven插件 <?xml version="1.0" encoding="UTF-8"?> <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
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.psmonster.wfe</groupId>
<artifactId>saxon</artifactId>
<packaging>jar</packaging>
<version>0.1.1</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>
<pluginRepositories>
<pluginRepository>
<id>maven2</id>
<url>https://repo.maven.apache.org/maven2/</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxp-api</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-B</artifactId>
<version>9.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-dependencies</artifactId>
<version>1.0.0.RELEASE</version>
<type>pom</type>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>central</id>
<name>saxon-releases</name>
<url>${env.MAVEN_REPO_URL}/repository/WFESRV/</url>
</repository>
</distributionManagement>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.2.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.7.0.1746</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>base.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
jar构建得很好,我可以在Docker容器中运行它。
因此,我只想把它推到我的Nexus工件库,我只是在重新打包后添加deploy。
然后,nice jar将被覆盖,一个只有已编译代码的小jar将被推送
有人知道如何在不使用deploy:deploy文件的情况下修复此问题吗?为什么不使用maven deploy插件来部署归档文件。还有其他插件可用于执行此任务。如果您使用的是jenkins,那么部署设置也可以通过jenkins插件进行不同的管理。但是现在,在本地机器中使用maven,我们可以使用nexus服务器凭据设置.m2设置文件。之后,您可以使用以下内容配置pom.xml:
<distributionManagement>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>${repository_url}</url>
</snapshotRepository>
</distributionManagement>
为什么不使用maven deploy插件来部署归档文件呢?还有其他插件可以执行此任务。如果您使用的是jenkins,那么部署设置也可以通过jenkins插件进行不同的管理。但是现在,在本地机器中使用maven,我们可以使用nexus服务器凭据设置.m2设置文件。之后,您可以使用以下内容配置pom.xml:
<distributionManagement>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>${repository_url}</url>
</snapshotRepository>
</distributionManagement>
所以。最后,它使用以下方法修复了它:
- mvn $MAVEN_CLI_OPTS deploy:deploy-file -DpomFile=pom.xml -DrepositoryId=central
-Dfile=target/saxon-0.1.$CI_PIPELINE_ID.jar
-Durl=http://psmonster:8081/repository/WFESRV/
所以。最后,它使用以下方法修复了它:
- mvn $MAVEN_CLI_OPTS deploy:deploy-file -DpomFile=pom.xml -DrepositoryId=central
-Dfile=target/saxon-0.1.$CI_PIPELINE_ID.jar
-Durl=http://psmonster:8081/repository/WFESRV/
不要将spring boot maven插件绑定到部署阶段。。按文档记录的阶段保存插件本身会导致它知道如何处理..mvn clean deploy…抱歉,我在这里粘贴了错误的内容。我编辑了以上内容。不会更改我以前的评论。使用简单的mvn clean deploy无目标调用…为什么手动调用spring boot:repackage目标?因为如果我这样做,mvn clean deploy只会将7.4k推送到Nexus。我编辑并添加了整个POM。也许你能更清楚地看到我做错了什么。Thxdo没有将spring boot maven插件绑定到部署阶段。。按文档记录的阶段保存插件本身会导致它知道如何处理..mvn clean deploy…抱歉,我在这里粘贴了错误的内容。我编辑了以上内容。不会更改我以前的评论。使用简单的mvn clean deploy无目标调用…为什么手动调用spring boot:repackage目标?因为如果我这样做,mvn clean deploy只会将7.4k推送到Nexus。我编辑并添加了整个POM。也许你能更清楚地看到我做错了什么。Thx@markus0074你能说清楚一点吗。所以,您的jar被推到了nexus中,但是jar的大小很小,不是fatJar吗?这是你的问题吗?是的。罐子里没有springboot的东西。@markus0074你能说清楚一点吗。所以,您的jar被推到了nexus中,但是jar的大小很小,不是fatJar吗?这是你的问题吗?是的。罐子里没有springboot的东西。
- mvn $MAVEN_CLI_OPTS deploy:deploy-file -DpomFile=pom.xml -DrepositoryId=central
-Dfile=target/saxon-0.1.$CI_PIPELINE_ID.jar
-Durl=http://psmonster:8081/repository/WFESRV/