简体   繁体   English

Gradle 无法解决 sikulixapi

[英]Gradle Unable to resolve sikulixapi

I'm trying to change my project from Maven to Gradle and I have problem with some dependencies.我正在尝试将我的项目从 Maven 更改为 Gradle 并且我遇到了一些依赖项问题。

here is my build.gradle file:这是我的 build.gradle 文件:

plugins {
    id 'java'
}

group 'de.myurl.test'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    jcenter()
    maven {
        url 'https://repo.spring.io/snapshot/'
    }
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile group: 'jxgrabkey', name: 'jxgrabkey', version: '1.0'
    compile 'org.seleniumhq.selenium:selenium-server:3.9.1'
    compile 'net.java.dev.jna:jna-platform:4.0.0'
    compile 'log4j:log4j:1.2.17'
    compile 'com.sikulix:sikulixapi:1.1.0'
    compile 'net.java.dev.jna:jna:5.4.0'
    compile 'com.relevantcodes:extentreports:2.41.0'
    compile 'commons-io:commons-io:2.6'
    compile 'javax.activation:activation:1.1.1'
    compile 'com.sun.xml.ws:policy:2.3.1'
    compile 'com.sun.jmx:jmxri:1.2.1'
    compile 'javax.mail:mail:1.4'
    compile 'com.uttesh:pdfngreport:2.1.3'
    compile 'org.uncommons:reportng:1.1.4'
    compile 'org.testng:testng:7.0.0'
}

and here is the problem with the dependencies:这是依赖项的问题:

在此处输入图像描述

I also tried to use other versions of sikuli but that didn't work either.我也尝试使用其他版本的 sikuli,但这也不起作用。 is it possible that this problem is related to the structure of my project?这个问题可能与我的项目结构有关吗?

I really appreciate any helps:)我真的很感激任何帮助:)

As you have shown in the screenshot, Gradle tries to resolve a dependency called com.sikulix:${sikulix.libs}:1.1.0 .如屏幕截图所示,Gradle 尝试解决名为com.sikulix:${sikulix.libs}:1.1.0的依赖项。 Of cause, there is a place holder here called ${sikulix.libs} that hasn't been substituted.当然,这里有一个名为${sikulix.libs}的占位符尚未被替换。

The place holder is actually defined in a Maven profile in the pom file for sikuli .占位符实际上是在 sikuli 的pom 文件中的 Maven 配置文件中定义的。 The relevant parts are these:相关部分如下:

<profiles>
    <profile>
        <id>Windows</id>
        <activation>
            <os>
                <family>windows</family>
            </os>
        </activation>
        <properties>
            <sikulix.libs>sikulixlibswin</sikulix.libs>
        </properties>
    </profile>
    <profile>
        <id>Unix</id>
        <activation>
            <os>
                <family>unix</family>
            </os>
        </activation>
        <properties>
            <sikulix.libs>sikulixlibslux</sikulix.libs>
        </properties>
    </profile>
    <profile>
        <id>Mac</id>
        <activation>
            <os>
                <family>mac</family>
            </os>
        </activation>
        <properties>
            <sikulix.libs>sikulixlibsmac</sikulix.libs>
        </properties>
    </profile>
</profiles>
<!-- ... -->
<dependency>
    <groupId>com.sikulix</groupId>
    <artifactId>${sikulix.libs}</artifactId>
    <version>${project.version}</version>
</dependency>

Unfortunately, Gradle doesn't support Maven profiles so you have to create a substitution rule yourself to fix it.不幸的是,Gradle 不支持 Maven 配置文件,因此您必须自己创建替换规则来修复它。 You can do it like this:你可以这样做:

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.name == '${sikulix.libs}') {
            def os = org.gradle.internal.os.OperatingSystem.current()
            def targetName
            if (os.isWindows()) {
                targetName = 'sikulixlibswin'
            } else if (os.isUnix()) {
                targetName = 'sikulixlibslux'
            } else if (os.isMacOsX()) {
                targetName = 'sikulixlibsmac'
            } else {
                throw new GradleException("Unknow operating system for determining the sikulix distribution")
            }
            details.useTarget group: details.requested.group, name: targetName, version: details.requested.version
            details.because 'The Maven dependency is relying on profiles to select the correct module name for the current operating system'
        }
    }
}

If you are using version 1.1.0, you may also have to define an additional Maven repository for one of the transitive dependencies called jxgrabkey .如果您使用的是 1.1.0 版,您可能还必须为名为jxgrabkey的传递依赖项之一定义额外的 Maven 存储库。 This repository is also defined in the pom, but will not be automatically used by Gradle.这个存储库也在 pom 中定义,但不会被 Gradle 自动使用。 You can add it like this:您可以像这样添加它:

repositories {
    maven {
        url = 'http://mvn.is.inf.uni-due.de:8081/nexus/content/repositories/atunes-dependencies/'
    }
}

But if you upgrade to the latest 1.1.1, this will not be necessary.但如果您升级到最新的 1.1.1,则不需要这样做。

try adding additional maven repo:尝试添加额外的 maven 回购:

repositories {
    jcenter()
    mavenCentral()
    maven {
        url 'https://repo.spring.io/snapshot/'
    }
}

And add grouping for sikuli并为 sikuli 添加分组

dependencies {
    compile group: 'org.sikuli', name: 'sikuli-api', version: '1.1.0'
}

Maven has also an id to be converted: Maven 还有一个要转换的id:

<dependencies>
    <dependency>
        <groupId>testName</groupId>
        <artifactId>testName</artifactId>
        <version>1.1.1</version>
    </dependency>
</dependencies>

will be converted to Gradle with this notation:将使用以下符号转换为 Gradle:

dependencies {
    implementation 'testName:testName:1.1.1' 
}

Also try to use implementation instead of compile.也尝试使用实现而不是编译。 after 2018 is deprecated syntax. 2018 年之后是不推荐使用的语法。

If build is not succeeded from this change try instead of implementation to use api as declaration.如果此更改未成功构建,请尝试使用api作为声明而不是实现 ex.前任。 api 'com.sikulix:sikulixapi:1.1.0'

After all it is a good choice to update library if applicable.毕竟,如果适用,更新库是一个不错的选择。

Hope that helps you!希望对你有帮助!

It works for me this way它以这种方式对我有用

dependencies {
    ... 
    compile files('sikulifolder/sikulixapi.jar')
    ...
}

sikulifolder - is a folder with jar in my project directory. sikulifolder - 是我的项目目录中带有 jar 的文件夹。 And don't forget that the dependencies order is important.并且不要忘记依赖顺序很重要。 I set it before the last selenium dependencies for example.例如,我将它设置在最后一个 selenium 依赖项之前。

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

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