0
votes

What I'm trying to do is to publish a Jar file into the Azure DevOps artifact using Gradle but I got this error massage:

FAILURE: Build failed with an exception.

  • What went wrong: Task 'publish' not found in root project 'Project1'.

  • Try: Run gradle tasks to get a list of available tasks. 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 1s

and the Build.gradle file is this:

apply plugin: 'java' 
apply plugin: 'maven-publish' 

publishing { 
    publications { 
        myPublication(MavenPublication) { 
            groupId 'soft' 
            artifactId 'crypto-utils' 
            version '5.2.0' 
            artifact 'C:\Users\d\Desktop\Project1\crypto-utils-5.2.0.jar' 
        } 
    } 

    // Repositories *to* which Gradle can publish artifacts 
    repositories { 
        maven { 
            url 'https://pkgs.dev.azure.com/soft/pm/_packaging/myFeed/maven/v1' 
            credentials { 
                username "myFeed"
                //The Azure DevOps Services build system will use the "SYSTEM_ACCESSTOKEN" to authenticate to Azure DevOps Services feeds 
                password System.getenv("AZURE_ARTIFACTS_ENV_ACCESS_TOKEN") != null ? System.getenv("AZURE_ARTIFACTS_ENV_ACCESS_TOKEN") : vstsMavenAccessToken 
            } 
        } 
    } 
} 
 
// Repositories *from* which Gradle can download dependencies; it's the same as above in this example
repositories { 
    maven { 
        url 'https://pkgs.dev.azure.com/soft/pm/_packaging/myFeed/maven/v1' 
        credentials { 
            username "myFeed" 
            //The Azure DevOps Services build system will use the "SYSTEM_ACCESSTOKEN" to authenticate to Azure DevOps Services feeds 
            password System.getenv("AZURE_ARTIFACTS_ENV_ACCESS_TOKEN") != null ? System.getenv("AZURE_ARTIFACTS_ENV_ACCESS_TOKEN") : vstsMavenAccessToken 
        } 
    } 
}

Any help please

1
Hi there, please check whether my answer below can help you. :) If not, could you please provide a sample of your pipeline task and your log, so that people have further investigation about this question.Jane Ma-MSFT
Hi there, is there any updates for this question? Please feel free to let me know whether my answer below can help you and feel free to comment~ Just a remind of this.Jane Ma-MSFT

1 Answers

-1
votes

The problem may be caused by using gradle in the wrong path. You need to run gradle in the same directory as the Build.gradle file.

If you are using Azure DevOps build pipeline, the root directory path of the repository is $(system.defaultworkingdirectory).

Other than that, you can try gradle clean build instead of gradle build.