如何在Jfrog Artifactory中部署数百个jar文件

huangapple go评论93阅读模式
英文:

How to deploy 100s of jars in Jfrog Artifactory

问题

我正在将Java项目的构建系统从Ant迁移到Maven的过程中,有将近700个依赖的JAR文件存放在一个文件夹中,但没有任何版本或包信息。

我已经成功地通过哈希值找出了其中超过400个JAR文件的Maven坐标。因此,对于剩下的300多个JAR文件,我打算直接上传到Artifactory的本地仓库中,然后自动生成Maven坐标。

就我目前所了解的情况探索,实现这一目标的唯一方法是通过Artifactory的UI手动部署/上传每个JAR文件,并启用Deploy as Maven Artifact选项以自动生成坐标,但这是非常耗时的过程(我想要为300多个文件执行此操作)。

是否有其他更有效的方法可行?

英文:

I was in the process of converting java projects build system from Ant to Maven and there are literally 700+ dependency jar files lying in a folder without any version or package information.

I was able to figure out maven co-ordinates for 400+ of those jar files using it's hash. So for the remaining 300+ jar files I am thinking of uploading it directly to a local repo in Artifactory and then generate maven co-ordinates automatically.

As far as i have explored the only way to achieve this is to deploy/upload every jar file manually via Artifactory UI with Deploy as Maven Artifact option enabled to generate co-ordinates automatically but this is a very time consuming process (I want to do this for 300+ files).

is there any other efficient way to do it?

答案1

得分: 2

我相信你已经找到了解决方案,但是对于其他需要类似操作的人来说,我最终使用Gradle来完成。我创建了一个简单的Gradle项目,并使用以下build.gradle文件。它从指定的目录收集所有的JAR文件,遍历它们并为每个JAR文件创建发布(publication)。我们希望使用子文件夹结构作为groupId,因此在其中有一些格式化逻辑。

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.21.0"
    }
}

apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"

version = '0.2021.0'

ext.thirdPartyLib = fileTree(dir: "$rootDir/../extrajars", include: ['**/*.jar'])

publishing {
    publications {
        thirdPartyLib.each { jar ->
            def fbase = jar.name.minus(".jar")
            "$fbase"(MavenPublication) {
                artifact jar
                artifactId fbase

                // 使用文件夹结构作为groupId
                def path = jar.path.minus("\\" + jar.name)
                path = path.replaceAll("\\\\", ".")
                path = path.replaceAll("c:/pathtoDirectory", "")
                groupId = path
            }
        }
    }
}

artifactory {
    contextUrl = 'http://yourArtifactoryUrl'
    publish {
        repository {
            repoKey = 'yourRepo'
            username = 'username'
            password = 'password'
        }
        defaults {
            thirdPartyLib.each { jar ->
                def fbase = jar.name.minus(".jar")
                publications(fbase)
            }
        }
    }
}

请注意,这是你提供的代码的中文翻译,不包括代码的解释或其他信息。

英文:

I'm sure you already figured out a solution, but for anyone else who has to do something similar I ended up just using gradle to do it for me. I created a bare gradle project and with the following build.gradle. It collects all the jars from the directory specified and loops through them and creates publications for each. We wanted to use the sub-folder structure as the groupId so there's a bit of logic to format that in there.

buildscript {
	repositories {
	  jcenter()
	}
	dependencies {
	  classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.21.0"
	}
 }

apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"

version = '0.2021.0'

ext.thirdPartyLib = fileTree(dir: "$rootDir/../extrajars", include: ['**/*.jar'])
	
	publishing {
		publications {
		   thirdPartyLib.each{ jar->
			  def fbase = jar.name.minus(".jar")
			  "$fbase"(MavenPublication) {
				 artifact jar
				 artifactId fbase

				 //the following was to use the folder structure as the groupId
				 def path = jar.path.minus("\\" + jar.name)
				 path = path.replaceAll("\\\\", ".")
				 path = path.replaceAll("c:/pathtoDirectory", "")

				 groupId = path
			  }
		   }
		}
	 }
	 
	 artifactory {
	    contextUrl = 'http://yourArtifactoryUrl'
	    publish {
	       repository {
	          repoKey='yourRepo'
	          username='username'
	          password='password'
	       }
	       defaults {
	         thirdPartyLib.each{ jar->
	            def fbase = jar.name.minus(".jar")
	            publications( fbase )
	          }
	       }
	    }
	 }

答案2

得分: 1

我看到有两种方法可以实现您想要的,不幸的是,两者都不是“开箱即用”的...

  1. 使用命令行客户端将每个 JAR 文件上传到 Artifactory。
    上传的主要命令是:

    jfrog rt upload foo.jar maven-local-repo

    更多细节请参见 https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory

    使用一个 bash 脚本循环处理 JAR 文件,对于每个文件,将其上传到单独的位置,生成一个简短的 POM 文件(从示例 POM 文件中生成,使用一些 sed 命令将 groupId 和 artifactId 替换为文件名),然后将其与 JAR 文件一起上传。

  2. 由于 Artifactory 在其 Web 应用程序中提供了此选项,您可以创建一个 Selenium 客户端,对每个 JAR 文件进行循环,连接到 Artifactory UI,并使用“生成默认 POM”选项上传每个文件。

    请参阅 https://www.jfrog.com/confluence/display/JFROG/Deploying+Artifacts#DeployingArtifacts-DeployingMavenArtifacts

英文:

I see two ways to achieve what you want, unfortunately none is available "out of the box"...

  1. Use the command line client to upload each JAR file to Artifactory.
    The main command to upload is:

    jfrog rt upload foo.jar maven-local-repo

See https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory for more details

Use a bash script to loop on the JAR files, and for each file, upload it to a separate location, generate a short pom (from a sample pom and some sed to replace groupId and artifactId with the filename) and upload it next to the JAR file.

  1. As Artifactory provides this option over its webapp, create a Selenium client that loops on each JAR file, connects to the Artifactory UI, and uploads each file using the "Generate default POM" option.

See https://www.jfrog.com/confluence/display/JFROG/Deploying+Artifacts#DeployingArtifacts-DeployingMavenArtifacts

huangapple
  • 本文由 发表于 2020年5月5日 17:46:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/61610199.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定