简体   繁体   English

仅从 Maven WAR 项目部署类 JAR

[英]Only deploy classes JAR from a Maven WAR Project

I have a Maven project which creates a WAR file as well as a JAR file (with the -classes classifier, using <attachClasses>true</attachClasses> in the maven-war-plugin config).我有一个 Maven 项目,它创建一个 WAR 文件和一个 JAR 文件(使用-classes分类器,在maven-war-plugin配置中使用<attachClasses>true</attachClasses> )。 When I run mvn deploy , both of these artifacts gets deployed to Maven Central (via Sonatype Nexus).当我运行mvn deploy ,这两个工件都被部署到 Maven Central(通过 Sonatype Nexus)。

That's all very well, but it's not really necessary to deploy the WAR to Maven Central - just deploying the -classes JAR would be sufficient, since the WAR is always uploaded to our github site for download, and only the JAR will ever be used as a dependency to another project.这一切都很好,但并不是真的需要将 WAR 部署到 Maven Central - 只需部署-classes JAR 就足够了,因为 WAR 总是上传到我们的 github 站点以供下载,并且只有 JAR 将永远用作对另一个项目的依赖。

Is there a way to configure this in Maven?有没有办法在 Maven 中配置它? I thought that <primaryArtifact>false</primaryArtifact> in the maven-war-plugin config might fix it, but it did not.我认为maven-war-plugin配置中的<primaryArtifact>false</primaryArtifact>可能会修复它,但它没有。

According to the Maven WAR Plugin FAQs , this problem needs a bit of refactoring in order to be solved.根据Maven WAR Plugin FAQs ,这个问题需要一些重构才能解决。 You would have to split the project into one "classes" module that only produces the classes JAR, and a second module which builds the whole webapp into a WAR file.您必须将项目拆分为一个“类”模块,该模块仅生成 JAR 类,以及将整个 web 应用程序构建为 WAR 文件的第二个模块。 The WAR module can then include the JAR module as a dependency.然后,WAR 模块可以包含 JAR 模块作为依赖项。

Different Maven profiles (one for building and deploying the JAR, another one to build the WAR and skip deployment) might be a solution too.不同的 Maven 配置文件(一个用于构建和部署 JAR,另一个用于构建 WAR 和跳过部署)也可能是一种解决方案。 But to be honest, that seems rather hacky and harder to maintain.但老实说,这似乎相当棘手且难以维护。 I am not sure that it would make your life easier in the long run.我不确定从长远来看它会让你的生活更轻松。

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

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