在Gradle中,我们如何为第三方传递依赖项执行”mvn install:install-file”?

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

How we can do mvn install:install-file for in gradle for 3rd party transient dependencies?

问题

我们有Bouncycastle依赖项,来自一个依赖项和另一个依赖项。它们大致如下:

implementation 'org.bouncycastle:bcprov-jdk14:1.61' <- 明确添加

'bouncycastle:bcprov-jdk14:138' <- 来自另一个依赖项

它们具有不同的组名,所以我不能只排除138。但我也不能将其增加到161,因为它在仓库中没有。

我能在我的Gradle脚本中设置一些东西吗,以便:

  1. 获取org.bouncycastle:bcprov-jdk14:1.61的jar文件

  2. 做类似于

    mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

    但使用Gradle,我将放置所需的格式,如bouncycastle:bcprov-jdk14:161

  3. 然后再执行其余的构建?

更新

出于某种奇怪的原因,甚至是Maneesha答案的错误版本也帮助了我。我没有成功地将jar文件放置在安装之前,但它起作用了!

configurations {
    bouncyCastle
}

dependencies {
    // 其他依赖项...

    bouncyCastle 'org.bouncycastle:bcprov-jdk14:1.61'
}

task installBouncyCastleJar {
    doLast {
        def bcFile = file('lib/bcprov-jdk14-1.61.jar')
        def groupId = 'bouncycastle'
        def artifactId = 'bcprov-jdk14'
        def version = '161'
        def packaging = 'jar'

        //project.repositories.mavenInstaller.install([
        //        file: bcFile,
        //        groupId: groupId,
        //        artifactId: artifactId,
        //        version: version,
        //        packaging: packaging
        //])
    }
}

project.afterEvaluate {
   build.dependsOn(installBouncyCastleJar)
}

我不知道具体是如何实现的,但使用

bouncyCastle 'org.bouncycastle:bcprov-jdk14:1.61'

并将bouncyCastle作为单独的配置,使得bouncycastle:bcprov-jdk14:138从Gradle的"effective pom"或类似的位置以及jar的/lib文件夹中消失。因此,不需要实际的Maven安装。如果不添加这个配置,没有任何排除操作可以将其移除。

英文:

We have Bouncycastle dependencies, coming from one dependency and another one. Sothey are something like that:

implementation &#39;org.bouncycastle:bcprov-jdk14:1.61&#39; <- explicitly added

&#39;bouncycastle:bcprov-jdk14:138&#39; <- taken from another dependency

They have the different group name, so I can't just exclude 138. But I can't inrement it to 161 too, as is hosts nowhere in the repos.

Can I set up something to my Gradle script to

  1. Take org.bouncycastle:bcprov-jdk14:1.61 jar

  2. Do something like

    mvn install:install-file -Dfile=&lt;path-to-file&gt; -DgroupId=&lt;group-id&gt; -DartifactId=&lt;artifact-id&gt; -Dversion=&lt;version&gt; -Dpackaging=&lt;packaging&gt;

but with Gradle where I'll put the desired format like bouncycastle:bcprov-jdk14:161

  1. Only then do the rest of the build?

UPD

For strange reason even broken version of Maneesha's answer helped me. I haven't succeed with the correct placing of the jar file before installing it, but it worked!

configurations {
    bouncyCastle
}

dependencies {
    // Other dependencies...
    
    bouncyCastle &#39;org.bouncycastle:bcprov-jdk14:1.61&#39;
}

task installBouncyCastleJar {
    doLast {
        def bcFile = file(&#39;lib/bcprov-jdk14-1.61.jar&#39;)
        def groupId = &#39;bouncycastle&#39;
        def artifactId = &#39;bcprov-jdk14&#39;
        def version = &#39;161&#39;
        def packaging = &#39;jar&#39;
        
        //project.repositories.mavenInstaller.install([
        //        file: bcFile,
        //        groupId: groupId,
        //        artifactId: artifactId,
        //        version: version,
        //        packaging: packaging
        //])
    }
}

project.afterEvaluate {
   build.dependsOn(installBouncyCastleJar)
}

I don't know how exactly, but using of

bouncyCastle &#39;org.bouncycastle:bcprov-jdk14:1.61&#39;

and bouncyCastle as separate configuration, made that bouncycastle:bcprov-jdk14:138 has disappeared from the "effective pom" or how it is called for Gradle and disappeared from the jar's/lib folder. So, no actual maven install was needed. Without adding the configuration, no exclusion helped to remove it.

答案1

得分: 1

你可以在拥有Jar文件时在本地进行操作。在你的项目目录中创建一个名为lib的文件夹来存储Bouncy Castle的JAR文件。将bcprov-jdk14-1.61.jar文件放在lib文件夹中。

修改你的Gradle脚本(build.gradle)以包含以下配置,configurations块定义了一个名为bouncyCastle的自定义配置:

configurations {
    bouncyCastle
}

dependencies {
    // 其他依赖...
    
    bouncyCastle 'org.bouncycastle:bcprov-jdk14:1.61'
}

task installBouncyCastleJar {
    doLast {
        def bcFile = file('lib/bcprov-jdk14-1.61.jar')
        def groupId = 'bouncycastle'
        def artifactId = 'bcprov-jdk14'
        def version = '161'
        def packaging = 'jar'
        
        project.repositories.mavenInstaller.install([
                file: bcFile,
                groupId: groupId,
                artifactId: artifactId,
                version: version,
                packaging: packaging
        ])
    }
}

project.afterEvaluate {
   build.dependsOn(installBouncyCastleJar)
}
英文:

You can do it locally when you have the Jar file. Create a folder named lib in your project directory to store the Bouncy Castle JAR file. Place the bcprov-jdk14-1.61.jar file in the lib folder.

Modify your Gradle script (build.gradle) to include the following configuration,The configurations block defines a custom configuration named bouncyCastle

configurations {
    bouncyCastle
}

dependencies {
    // Other dependencies...
    
    bouncyCastle &#39;org.bouncycastle:bcprov-jdk14:1.61&#39;
}

task installBouncyCastleJar {
    doLast {
        def bcFile = file(&#39;lib/bcprov-jdk14-1.61.jar&#39;)
        def groupId = &#39;bouncycastle&#39;
        def artifactId = &#39;bcprov-jdk14&#39;
        def version = &#39;161&#39;
        def packaging = &#39;jar&#39;
        
        project.repositories.mavenInstaller.install([
                file: bcFile,
                groupId: groupId,
                artifactId: artifactId,
                version: version,
                packaging: packaging
        ])
    }
}

project.afterEvaluate {
   build.dependsOn(installBouncyCastleJar)
}

huangapple
  • 本文由 发表于 2023年6月8日 17:09:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76430284.html
匿名

发表评论

匿名网友

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

确定