使用分类器部署工件时 Maven 部署到 Nexus 失败

Maven Deploy to Nexus Fails When Deploying Artifact with Classifier

全部,

我有一个 Spring 启动应用程序,它需要作为库和可执行 jar 部署到 Nexus。 Spring 提供了一种在 POM 文件中使用以下代码的方法。

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <version>1.5.3.RELEASE</version>
      <configuration>
        <classifier>exec</classifier>
      </configuration>
    </plugin>
  </plugins>
</build>

这会生成以下两个 JAR。

(a) target/[artifact]-[version].jar
(b) target/[artifact]-[version]-exec.jar

在将代码添加到 POM 之前,我能够毫无问题地将工件 (a) 部署到 Nexus。但是,一旦我添加代码,就会出现以下异常。

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project [artifact-id]: Failed to deploy artifacts: Could not find artifact [group-id]:[artifact-id]:jar:exec:[version]-[iteration] in nexus.ftc.lab ([nexus-url])
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
  at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
  at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
  at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
  at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
  at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
  at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
  at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
  at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
  at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
  at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:497)
  at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
  at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
  at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
  at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to deploy artifacts: Could not find artifact [group-id]:[artifact-id]:jar:exec:[version]-[iteration] in nexus.ftc.lab ([nexus-url])
  at org.apache.maven.plugin.deploy.DeployMojo.deployProject(DeployMojo.java:284)
  at org.apache.maven.plugin.deploy.DeployMojo.execute(DeployMojo.java:169)
  at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
  ... 20 more
Caused by: org.apache.maven.artifact.deployer.ArtifactDeploymentException: Failed to deploy artifacts: Could not find artifact [group-id]:[artifact-id]:jar:exec:[version]-[iteration] in nexus.ftc.lab ([nexus-url])
  at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:143)
  at org.apache.maven.plugin.deploy.AbstractDeployMojo.deploy(AbstractDeployMojo.java:171)
  at org.apache.maven.plugin.deploy.DeployMojo.deployProject(DeployMojo.java:279)
  ... 23 more
Caused by: org.eclipse.aether.deployment.DeploymentException: Failed to deploy artifacts: Could not find artifact [group-id]:[artifact-id]:jar:exec:[version]-[iteration] in nexus.ftc.lab ([nexus-url])
  at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:317)
  at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:245)
  at org.eclipse.aether.internal.impl.DefaultRepositorySystem.deploy(DefaultRepositorySystem.java:413)
  at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:139)
  ... 25 more
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact [group-id]:[artifact-id]:jar:exec:[version]-[iteration] in nexus.ftc.lab ([nexus-url])
  at io.takari.aether.connector.AetherRepositoryConnector.wrap(AetherRepositoryConnector.java:893)
  at io.takari.aether.connector.AetherRepositoryConnector.wrap(AetherRepositoryConnector.java:1)
  at io.takari.aether.connector.AetherRepositoryConnector$PutTask.flush(AetherRepositoryConnector.java:743)
  at io.takari.aether.connector.AetherRepositoryConnector.put(AetherRepositoryConnector.java:345)
  at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:311)
  ... 28 more

增加阴谋。我尝试使用更标准的代码构建另一个 JAR。当我使用它进行部署时,它工作正常。

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <executions>
        <execution>
        <phase>package</phase>
        <goals>
         <goal>jar</goal>
        </goals>
        <configuration>
         <classifier>client</classifier>
        </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

再更新一次,当我尝试下面的操作时,它失败并出现相同的异常。

<build>
  <plugins>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
           <execution>
              <phase>package</phase>
              <goals>
                 <goal>shade</goal>
              </goals>
              <configuration>
                 <shadedArtifactAttached>true</shadedArtifactAttached>
                 <shadedClassifierName>fat</shadedClassifierName>
              </configuration>
           </execution>
        </executions>
     </plugin>

  </plugins>
</build>

此问题是由 IIS 代理中的请求过滤限制引起的。

默认情况下,允许的最大内容长度为 30 MB。这阻止了我的 post 的 ~90 MB jar 文件。将限制增加到 512 MB 解决了这个问题。