You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何检测Maven构件的发布/快照版本?部署至Artifactory的相关疑问

Great questions! Let's break them down one by one:

1. How to detect if a Maven artifact is a release or snapshot version?

Maven uses a clear naming convention to differentiate between release and snapshot builds, so there are several straightforward ways to check:

  • Check the version string directly: This is the simplest method. If the artifact's version ends with -SNAPSHOT (case-sensitive), it’s a snapshot build. Examples:
    • 2.3.1-SNAPSHOT → Snapshot version
    • 2.3.1 → Release version
  • Inspect the artifact filename: When you build or download the artifact, the filename will reflect its version type. Snapshot artifacts often include a timestamp suffix (like my-lib-2.3.1-20240520.143022-5.jar), while release artifacts use the exact, fixed version number (e.g., my-lib-2.3.1.jar).
  • Use Maven's help command: To verify details remotely or get structured information, run this command (replace placeholders with your artifact's details):
    mvn help:describe -DgroupId=com.yourcompany -DartifactId=your-lib -Dversion=2.3.1-SNAPSHOT -Ddetail
    
    Look for the version field in the output—if it includes -SNAPSHOT, it’s a snapshot. Release versions will show a fixed string without that suffix.
2. Specifying release/snapshot repositories for mvn deploy:deploy-file

When deploying artifacts to Artifactory with deploy:deploy-file, you need to map the artifact type (release/snapshot) to the correct repository URL and authenticate via your Maven settings.xml. Here's how to do it properly:

Step 1: Configure repositories and servers in settings.xml

First, add server credentials and repository definitions to your ~/.m2/settings.xml (or the global settings.xml in your Maven installation). You’ll want separate entries for release and snapshot repositories:

<settings>
  <servers>
    <!-- Credentials for release repository -->
    <server>
      <id>artifactory-releases</id>
      <username>your-artifactory-username</username>
      <password>your-artifactory-password</password>
    </server>
    <!-- Credentials for snapshot repository -->
    <server>
      <id>artifactory-snapshots</id>
      <username>your-artifactory-username</username>
      <password>your-artifactory-password</password>
    </server>
  </servers>

  <profiles>
    <profile>
      <id>artifactory-repos</id>
      <repositories>
        <repository>
          <id>artifactory-releases</id>
          <url>https://your-artifactory-instance/artifactory/libs-release-local</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>false</enabled></snapshots>
        </repository>
        <repository>
          <id>artifactory-snapshots</id>
          <url>https://your-artifactory-instance/artifactory/libs-snapshot-local</url>
          <releases><enabled>false</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <!-- Optional: Activate the profile by default to avoid specifying it in commands -->
  <activeProfiles>
    <activeProfile>artifactory-repos</activeProfile>
  </activeProfiles>
</settings>

Step 2: Deploy with the correct repository parameters

Run the deploy:deploy-file command with parameters matching your artifact’s type:

For a release artifact (version without -SNAPSHOT):

mvn deploy:deploy-file \
  -DgroupId=com.yourcompany \
  -DartifactId=your-app \
  -Dversion=2.3.1 \
  -Dpackaging=war \
  -Dfile=/path/to/your-app-2.3.1.war \
  -DrepositoryId=artifactory-releases \
  -Durl=https://your-artifactory-instance/artifactory/libs-release-local

For a snapshot artifact (version with -SNAPSHOT):

mvn deploy:deploy-file \
  -DgroupId=com.yourcompany \
  -DartifactId=your-lib \
  -Dversion=2.3.2-SNAPSHOT \
  -Dpackaging=jar \
  -Dfile=/path/to/your-lib-2.3.2-SNAPSHOT.jar \
  -DrepositoryId=artifactory-snapshots \
  -Durl=https://your-artifactory-instance/artifactory/libs-snapshot-local

Key notes:

  • The repositoryId must exactly match the <id> of the <server> entry in settings.xml—this is how Maven retrieves authentication credentials.
  • Adjust the Artifactory URL paths to match your instance’s setup (Artifactory commonly uses libs-release-local and libs-snapshot-local, but your admin might have custom names).
  • If you activated the profile in settings.xml, you can omit the -Durl parameter, but explicitly specifying it avoids ambiguity.

内容的提问来源于stack exchange,提问作者Khoda

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:09:53