英文:
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脚本中设置一些东西吗,以便:
-
获取
org.bouncycastle:bcprov-jdk14:1.61
的jar文件 -
做类似于
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
但使用Gradle,我将放置所需的格式,如bouncycastle:bcprov-jdk14:161
-
然后再执行其余的构建?
更新
出于某种奇怪的原因,甚至是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 'org.bouncycastle:bcprov-jdk14:1.61'
<- explicitly added
'bouncycastle:bcprov-jdk14:138'
<- 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
-
Take
org.bouncycastle:bcprov-jdk14:1.61 jar
-
Do something like
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
but with Gradle
where I'll put the desired format like bouncycastle:bcprov-jdk14:161
- 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 '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)
}
I don't know how exactly, but using of
bouncyCastle 'org.bouncycastle:bcprov-jdk14:1.61'
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 '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)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论