I am using Gradle version 6.7.1, Currently, in my application I facing an issue with the maven publishing task.
We have kept the publishing task in the central location Gradle file named ( nexusgradle-1.0.5.gradle) and importing it via
apply from
the content of the central location Gradle (nexusgradle-1.0.5.gradle) is the below which contain the information of nexus repo for snapshot and release along with user credentials for pushing artefacts to nexus.
apply plugin: ‘maven-publish’
publishing { publications { mavenJava(MavenPublication) { from components.web } } repositories { maven { credentials { username 'uploader' password 'uploaderpassword' } name 'Nexus_Repo' def releasesRepoUrl = 'http://<hostname>/repository/<maven-releases>/' def snapshotsRepoUrl = 'http://<hostname>/repository/<maven-snapshots>/' url = project.version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl } }
The application Gradle ( build.gradle) looks like the one below
import org.apache.tools.ant.filters.ReplaceTokens
plugins { id 'war' // Add git release plugin for versioning snaphots and release builds id 'pl.allegro.tech.build.axion-release' version '1.10.1' id 'org.springframework.boot' version '2.1.4.RELEASE' // Add Git properties plugin. id 'com.gorylenko.gradle-git-properties' version '2.2.0' id 'jacoco' } // apply from center location apply from :'http://<hostaname>/repository/thirdparty/com/mf/nexusgradle/1.0.5/nexusgradle-1.0.5.gradle' repositories { maven { url = 'http://<hostname>/repository/groupRepo/' } jcenter() } test { testLogging.showStandardStreams = true maxParallelForks = 3 ignoreFailures = true // to skip test Failures testLogging { //logging the test exceptionFormat = 'full' events "passed", "skipped", "failed" } } jacoco { toolVersion = '0.8.3' } jacocoTestReport { dependsOn test // tests are required to run before generating the report reports { xml.enabled true //enabling for generate xml for to capture data in sonarqube server } } // Customize Git properties plugin. gitProperties { // Change date format in git.properties file. dateFormat = "yyyy-MM-dd HH:mm:ssZ" dateFormatTimeZone = 'GMT' } dependencies { implementation 'org.springframework.boot:spring-boot:2.1.4.RELEASE' // mutliple import below } sourceCompatibility = '1.8' targetCompatibility = '1.8' scmVersion { repository { directory = project.rootProject.file('.') } } group = 'com.package' description = 'appname' project.version = scmVersion.version project.ext.timestamp = new Date().format("dd/MM/yyyy HH:mm:ss") processResources { filter ReplaceTokens, tokens:[BUILD_VERSION: project.version, BUILD_TIMESTAMP: project.ext.timestamp] } tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } war { enabled = true } springBoot { buildInfo() } bootWar { archiveClassifier = 'boot' mainClassName = 'com.package.appname.SpringBootRunner' }
when I run the Gradle command for publishing
`
gradlew clean build publish
The task will fail as the publishing task will try to push artefacts of the snapshot to the release repo instead of the snapshot repo
> Configure project : > Task :clean UP-TO-DATE > Task :bootBuildInfo > Task :compileJava Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. > Task :generateGitProperties > Task :processResources > Task :classes > Task :bootWar > Task :war > Task :assemble > Task :check > Task :build > Task :generateMetadataFileForMavenJavaPublication > Task :generatePomFileForMavenJavaPublication > Task :publishMavenJavaPublicationToNexus_RepoRepository FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':publishMavenJavaPublicationToNexus_RepoRepository'. > Failed to publish publication 'mavenJava' to repository 'Nexus_Repo' > Could not PUT 'http://<hostname>/repository/maven-releases/com/package/appname/1.0.9-SNAPSHOT/maven-metadata.xml'. Received status code 400 from server: Repository version policy: RELEASE does not allow metadata in path: com/package/appname/1.0.9-SNAPSHOT/maven-metadata.xml * 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.
But if I remove the apply from:
item and bring the Publishing task to the application Gradle ( child Gradle file) file it will work fine, the build artefact is pushed to snapshot repo without any issue.
Configure project :
Task :clean UP-TO-DATE
Task :bootBuildInfoTask :compileJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.Task :generateGitProperties
Task :processResources
Task :classes
Task :bootWar
Task :war
Task :assemble
Task :check
Task :build
Task :generateMetadataFileForMavenJavaPublication
Task :generatePomFileForMavenJavaPublication
Task :publishMavenJavaPublicationToNexus_RepoRepository
Task :publishDeprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use ‘–warning-mode all’ to show the individual deprecation warnings.
See Command-Line InterfaceBUILD SUCCESSFUL in 29s
10 actionable tasks: 9 executed, 1 up-to-date
Can someone guide me, what mistake I am making when putting the maven publishing task in a parent Gradle file? why child Gradle cant resolve values from the parent gradle file properly, is there some scope problem? how to resolve it