How does gradle use maven-publish to publish jar packages and upload to private maven
This article mainly introduces the relevant knowledge of "how gradle uploads jar packages to private maven using maven-publish". Xiaobian shows you the operation process through practical cases. The operation method is simple and fast and practical. I hope this article "how gradle uploads jar packages to private maven using maven-publish" can help you solve the problem.
1. Add the plugin apply plugin: 'maven-publish' 2. Add the following configuration//package source code task sourceJar(type: Jar) { from sourceSets.main.allJava}publishing { publications { maven(MavenPublication) { //Specify group/artifact/version information, which can be left blank. By default the project group/name/version is used as groupId/artifactId/version groupId project.group artifactId project.name version project.version //If war package, fill in components.web. If jar package, fill in components.java. from components.java //configure upload source code artifact sourceJar { classifier "sources" } } } repositories { maven { //Specify the maven private server repository to upload url = "http://jenkins.maxrocky.com:8080/maven/content/repositories/thirdparty/" //Authentication user and password credentials { username 'admin' password 'maxrocky5721' } } Execute the following command to upload gradle publishMavenPublicationToMavenRepository
Normal output results
gradle publishMavenPublicationToMavenRepository:common:generatePomFileForMavenPublication:common:compileJava UP-TO-DATE:common:processResources UP-TO-DATE: common:classes UP-TO-DATE: common:jar UP-TO-DAT:common:sourceJar UP-TO-DATE:common:publishMavenPublicationToMavenRepositoryUpload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.jarUpload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.jar.sha1Uploadhttp://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.jar.md5Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.pomUploadhttp://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/maven-metadata.xml.sha1Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.pom.sha1Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/maven-metadata.xml.md5BUILD SUCCESSFULTotal time: 1.906 secs http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/maven-metadata.xmlUpload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0-sources.jar.md5Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0-sources.jar.sha1Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0-sources.jarUpload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.pom.md5Upload
Sometimes errors occur, as shown below.
:common:generatePomFileForMavenPublication:common:compileJava UP-TO-DATE:common:processResources UP-TO-DATE:common:classes UP-TO-DATE:common:jar UP-TO-DATE:common:sourceJar UP-TO-DATE:common:publishMavenPublicationToMavenRepositoryUpload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.jarCould not transfer artifact com.kingboy:common:jar:1.0 from/to remote (http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/): Could not write to resource 'com/kingboy/common/1.0/common-1.0.jar'Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.pomCould not transfer artifact com.kingboy:common:pom:1.0 from/to remote (http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/): Could not write to resource 'com/kingboy/common/1.0/common-1.0.pom'Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0-sources.jarCould not transfer artifact com.kingboy:common:jar:sources:1.0 from/to remote (http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/): Could not write to resource 'com/kingboy/common/1.0/common-1.0-sources.jar':common:publishMavenPublicationToMavenRepository FAILEDFAILURE: Build failed with an exception.* What went wrong:Execution failed for task ':common:publishMavenPublicationToMavenRepository'.> Failed to publish publication 'maven' to repository 'maven' > Failed to deploy artifacts: Could not transfer artifact com.kingboy:common:jar:1.0 from/to remote (http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/): Could not write to resource 'com/kingboy/common/1.0/common-1.0.jar'* Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.BUILD FAILED
Mine is because of network reasons, change the network, try a few times to succeed, go to stackoverflow to see the following, there is no too clear reason.
About "gradle how to use maven-publish jar package upload to private maven" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.