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

Windows环境下Gradle构建找不到com.jfrog.artifactory插件求助

问题:Gradle构建失败,无法找到Artifactory插件

我有一个开发完成的后端项目,用IntelliJ和终端启动均失败。gradle.properties配置无误,但每次构建都会报错:

Build file 'C:\Users\Desktop\Land-Backend\build.gradle' line: 5
----------
Plugin [id: 'com.jfrog.artifactory', version: '4.33.1'] was not found in any of the following sources:
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
> BUILD FAILED in 6s

我已尝试删除.gradle和.idea目录,但问题仍未解决,怀疑是Windows系统在IntelliJ启动后自动修改文件,导致无法连接Artifactory。以下是我的build.gradle文件内容:

import org.gradle.api.services.BuildService
import org.gradle.api.services.BuildServiceParameters

plugins {
    id "com.jfrog.artifactory" version "4.33.1"
    id 'com.gorylenko.gradle-git-properties' version '2.4.1' apply false
    id 'jacoco'
    id 'java'
    id 'java-library'
    id 'org.liquibase.gradle' version '2.2.0'
    id 'org.sonarqube' version '4.2.1.3168'
    id 'org.springframework.boot' version '3.1.1' apply false
    id 'org.jetbrains.kotlin.jvm' version '1.9.0'
    id 'org.jetbrains.kotlin.plugin.jpa' version '1.9.0'
    id 'org.jetbrains.kotlin.plugin.spring' version '1.9.0'
}

def artifactoryAuthentication(MavenArtifactRepository repo) {
    repo.credentials(PasswordCredentials) {
        username = project.findProperty("artifactory_user") ?: "your-username"
        password = project.findProperty("artifactory_token_secret") ?: "your-token"
    }
}

def noParallelUsageService = project.getGradle().getSharedServices().registerIfAbsent(
        "noParallelUsageService",
        AbstractService.class,
        spec -> {
            spec.getMaxParallelUsages().set(1)
        }
)
	ext {
    platformVersion = '6.2.3'
}
def exclusionList = [
        "**/com/example/moduletemplate/configuration/*",
        "**/com/example/moduletemplate/YourApplication.java",
        "**/com/example/moduletemplate/service/configuration/*"
]
allprojects {
    group 'com.example.land'
    version '6.2.3'

    apply plugin: 'java-library'

    java {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    repositories {
        maven {
            url "${project.findProperty("artifactory_url") ?: 'your-artifactory-url'}/ap-releases/"
            artifactoryAuthentication it
        }
        maven {
            url "${project.findProperty("artifactory_url") ?: 'your-artifactory-url'}/ap-snapshots/"
            artifactoryAuthentication it
        }
        maven {
            url "${project.findProperty("artifactory_url") ?: 'your-artifactory-url'}/apache-maven/"
            artifactoryAuthentication it
        }
    }
}

subprojects {

    each {
        buildDir = "$project.rootDir/build/${project.path.replace(':', '/')}" as File
        afterEvaluate {
            if (!tasks.findByName('bootJar')?.enabled) {
                archivesBaseName = "${group}.${name}"
            }
        }

        tasks.withType(JavaCompile) {
            options.encoding = 'UTF-8'
            options.compilerArgs += [
                    '-Amapstruct.unmappedTargetPolicy=ERROR'
            ]
        }
    }

    // There is a problem with long paths on windows, so jacoco is not used than
    if (!System.properties['os.name'].toLowerCase().contains('windows')) {
        apply plugin: 'jacoco'
    }
    apply plugin: 'org.sonarqube'

    // let each subproject report the merged coverage report
    sonarqube {
        properties {
            property 'sonar.coverage.exclusions', exclusionList
            property 'sonar.coverage.jacoco.xmlReportPaths', "$project.rootDir/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml"
        }
    }

    testing {
        suites {
            test {
                targets {
                    configureEach {
                        testTask.configure {
                            finalizedBy jacocoTestReport
                            useJUnitPlatform()
                            maxHeapSize = "2048m"
                        }
                    }
                }
            }

            integrationTest(JvmTestSuite) {
                dependencies {
                    implementation project(':app')
                }

                sources {
                    java {
                        srcDirs = ['src/integrationTest/java']
                    }
                }

                targets {
                    configureEach {
                        testTask.configure {
                            shouldRunAfter(test)
                            usesService(noParallelUsageService)
                        }
                    }
                }
            }
        }
    }

    tasks.named('check') {
        dependsOn(testing.suites.integrationTest)
    }

    jacocoTestReport {
        reports {
            xml {
                enabled true
            }
            csv {
                enabled false
            }
            html {
                enabled false
            }
        }
    }

    dependencies {
        [
                'implementation', 'compileOnly', 'annotationProcessor',
                'testCompileOnly', 'testAnnotationProcessor',
                'integrationTestImplementation', 'integrationTestAnnotationProcessor',
        ].each {
            add it, enforcedPlatform("com.example:common-platform:${rootProject.ext.platformVersion}")
        }

        constraints {
            ...
        }

        implementation(
                'org.springframework.boot:spring-boot-starter-logging',
                'org.springframework.boot:spring-boot-starter-validation',
                'org.mapstruct:mapstruct',
                'org.mapstruct:mapstruct-processor'
        )

        compileOnly(
                'org.projectlombok:lombok',
                'com.google.code.findbugs:jsr305'
        )

        annotationProcessor(
                'org.projectlombok:lombok',
                'org.mapstruct:mapstruct',
                'org.mapstruct:mapstruct-processor',
                'org.projectlombok:lombok-mapstruct-binding',
                'org.mapstruct.extensions.spring:mapstruct-spring-extensions',
                'org.mapstruct.extensions.spring:mapstruct-spring-annotations',
                'org.mapstruct:mapstruct-processor',
                'org.hibernate:hibernate-jpamodelgen'
        )

        runtimeOnly(
                'com.h2database:h2'
        )

        testImplementation(
                'org.junit.jupiter:junit-jupiter',
                'org.assertj:assertj-core',
                'org.mockito:mockito-core',
                'org.mockito:mockito-junit-jupiter',
                'org.hamcrest:hamcrest',
                'org.springframework.boot:spring-boot-test'
        )

        testCompileOnly(
                'org.projectlombok:lombok'
        )

        testRuntimeOnly(
                'org.junit.platform:junit-platform-engine',
                'org.junit.platform:junit-platform-commons'
        )

        testAnnotationProcessor(
                'org.projectlombok:lombok',
                'org.mapstruct:mapstruct',
                'org.mapstruct:mapstruct-processor',
                'org.projectlombok:lombok-mapstruct-binding',
                'org.mapstruct.extensions.spring:mapstruct-spring-extensions',
                'org.mapstruct.extensions.spring:mapstruct-spring-annotations',
                'org.mapstruct:mapstruct-processor'
        )

        pluginManager.withPlugin('java-test-fixtures') {
            ['testFixturesImplementation', 'testFixturesAnnotationProcessor'].each {
                add it, enforcedPlatform("com.example:common-platform:${rootProject.ext.platformVersion}")
            }

            testFixturesImplementation(
                    'org.projectlombok:lombok',
                    'org.mapstruct:mapstruct',
                    'org.mapstruct:mapstruct-processor',
            )

            testFixturesAnnotationProcessor(
                    'org.projectlombok:lombok',
                    'org.mapstruct:mapstruct',
                    'org.mapstruct:mapstruct-processor',
                    'org.projectlombok:lombok-mapstruct-binding',
                    'org.mapstruct.extensions.spring:mapstruct-spring-extensions',
                    'org.mapstruct.extensions.spring:mapstruct-spring-annotations',
                    'org.mapstruct:mapstruct-processor'
            )
        }
    }

}

task codeCoverageReport(type: JacocoReport) {

    // Gather execution data from all subprojects
    executionData fileTree(project.rootDir.absolutePath).include("build/**/jacoco/*.exec")

    // Add all relevant sourceSets from the subprojects
    subprojects.each {
        sourceSets it.sourceSets.main
    }

    reports {
        xml.required = true
        csv.required = false
        html.required = false
    }
}

// always run the tests before generating the report
codeCoverageReport.dependsOn {
    subprojects*.check
}

// automatically create the codeCoverageReport after running check
check {
    finalizedBy codeCoverageReport
}

abstract class AbstractService implements BuildService<BuildServiceParameters.None> {}

解决方案

1. 配置插件仓库访问路径

Gradle默认从官方Plugin Portal拉取插件,但私有Artifactory插件需要额外配置仓库。在项目根目录的settings.gradle中添加以下配置:

pluginManagement {
    repositories {
        maven {
            url "${artifactory_url}/plugins-release-local" // 替换为你的Artifactory插件仓库地址
            credentials {
                username = artifactory_user
                password = artifactory_token_secret
            }
        }
        gradlePluginPortal() // 保留官方仓库作为备选
    }
}

2. 验证插件版本可用性

确认4.33.1版本的com.jfrog.artifactory插件存在于你的Artifactory仓库中。如果版本不存在,尝试升级到兼容的稳定版本,或联系管理员确认插件包是否已上传。

3. 解决Windows文件锁定问题

Windows系统可能锁定项目文件导致Gradle无法读取,执行以下步骤:

  • 关闭所有打开项目的IDE和终端窗口
  • 手动删除项目根目录下的.gradle文件夹(确保彻底删除)
  • 以管理员身份打开终端,执行gradle clean build

4. 直接在build.gradle中指定插件仓库

如果settings.gradle配置无效,可在build.gradle的plugins块前添加插件仓库配置:

pluginManagement {
    repositories {
        maven { url "${artifactory_url}/plugins-release-local" }
        gradlePluginPortal()
    }
}

plugins {
    id "com.jfrog.artifactory" version "4.33.1"
    // 其他插件配置...
}

5. 验证Gradle属性配置

检查gradle.properties中的artifactory_url、artifactory_user、artifactory_token_secret是否正确,无多余空格或特殊字符。可在终端执行以下命令验证配置:

gradle properties -PshowStandardProperties=true | findstr artifactory

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 08:22:03