Closed Ayvytr closed 1 year ago
The problem is that dependenciesNode
is not a variable.
So you need to get a hold of the dependencies
node of the POM. or create it if it doesn't exist.
You can do it like so:
def depenciesNode = asNode().getAt('dependencies')[0] ?: asNode().appendNode('dependencies')
Add this inside the pom.withXml
, but before the each
block
ignore
Here is my maven_push.gradle to upload my library:
apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' apply plugin: 'maven-publish'
group = PROJ_GROUP
// Both the artifactory and bintray plugins depend on this singular // global
version
variable. As such, we need to configure it based // on which task we're running. // // The solution here is brittle; it just checks whether 'bintrayUpload' // was called for execution, otherwise it assumes SNAPSHOT. If we // were to wait until the task graph was built, we'd be too late // (the plugins would already have usedversion
). version = PROJ_VERSION// Create source/javadoc artifacts for publishing task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier = 'sources' }
task javadoc(type: Javadoc) { // Exclude generated files exclude '/BuildConfig.java' exclude '/R.java' source = android.sourceSets.main.java.srcDirs failOnError false classpath += configurations.compile classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) }
task javadocJar(type: Jar, dependsOn: javadoc) { classifier = 'javadoc' from javadoc.destinationDir }
javadoc { options { encoding "UTF-8" charSet 'UTF-8' author true version true links "http://docs.oracle.com/javase/7/docs/api" title PROJ_NAME } }
artifacts { archives javadocJar archives sourcesJar }
// Configure android-maven-gradle-plugin install { repositories.mavenInstaller.pom.project { name PROJ_NAME description PROJ_DESCRIPTION packaging 'aar' url PROJ_WEBSITEURL
}
// Configure gradle-bintray-plugin (for publishing releases) bintray { Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream())
}
publishing { publications { mavenJava(MavenPublication) { pom.withXml { // Iterate over the implementation dependencies (we don't want the test ones), adding a node for each
configurations.implementation.allDependencies.each {
// Ensure dependencies such as fileTree are not included.
if (it.name != 'unspecified') {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}
Here is my error when I use maven_push.gradle to uploading my library:
Where: Script 'D:\Code\CodeRepository\Gank\ModularizationComponent\maven_push.gradle' line: 123
What went wrong: Execution failed for task ':base-adapter:generatePomFileForMavenJavaPublication'.
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.
Line 123 is here: def dependencyNode = dependenciesNode.appendNode('dependency')