Unable to publish single jar in multi project using gradle - java

The structure of multi project is
Root
+---ProjectA
+---ProjectB
+---ProjectC
+ ...
I want to publish a single consolidated jar file in
task allJar
build.gradle
buildscript {
repositories {
mavenLocal()
maven {
url "myurl"
credentials {
// Credentials needed to pull build dependencies from Nexus
username "$username"
password "$password"
}
}
}
}
apply plugin: "maven-publish"
apply plugin: "maven"
allprojects {
repositories {
mavenLocal()
maven {
credentials {
username "$username"
password "$password"
}
url "url"
}
group 'com.myproject'
version = '1.0.0-SNAPSHOT'
}
subprojects {
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceSets.main.java.srcDir "src/main/java"
sourceSets.main.resources.srcDirs "src/main/resources"
sourceSets.test.java.srcDir "src/test/java"
sourceSets.test.resources.srcDirs "src/test/resources"
dependencies {
// string utils
compile "org.apache.commons:commons-lang3:3.4"
testCompile "junit:junit"
}
compileJava.dependsOn(processResources)
}
}
subprojects.each { subproject ->
evaluationDependsOn(subproject.path)
}
task allJar(type: Jar, dependsOn: subprojects.assemble) {
baseName = project.name
subprojects.each { subproject ->
from subproject.configurations.archives.artifacts.files.collect {
zipTree(it)
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = project.name
from components.java
artifact allJar
println "Project Group: " + project.group + "\nProject Name: " + project.name + "\nProject Version: " + project.version
}
}
repositories {
maven {
credentials{
username NEXUS_USER
password NEXUS_PASS
}
url "myurl"
}
}
}
Problems
I am getting error during publish as
Invalid publication 'mavenJava': multiple artifacts with the identical extension and classifier ('jar', 'null
').
Adding a classifier :'all' in task allJar solves the issue but it creates 2 jars in root folder
build/libs/MyProject-1.0.0-SNAPSHOT.jar
build/libs/MyProject-1.0.0-SNAPSHOT-all.jar

Related

Artifactory publish with multi-module gradle

Hope all doing well.
Today I was working on multi-module gradle project, and trying to publish one of it's dependency to artifactory as well.
my project structure are:
build.gradle (main)
buildscript {
ext {
appVersion = "0.0.2-RC3"
appBuildCode = 2
// dependencies version
springVersion = "2.6.0"
swaggerApiVersion = "1.5.12"
jjwtVersion = "0.11.2"
lombokVersion = "1.18.22"
// firebase versions
firebaseAdminVersion = "8.1.0"
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springVersion")
classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.2.0")
classpath("io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE")
classpath("org.jfrog.buildinfo:build-info-extractor-gradle:latest.release")
}
}
apply(plugin: "org.sonarqube")
apply(plugin: "jacoco")
allprojects {
apply(plugin: 'java')
apply(plugin: 'org.springframework.boot')
apply(plugin: 'io.spring.dependency-management')
group 'com.example'
repositories {
mavenCentral()
maven {
url "${artifactory_contextUrl}/libs-release/"
allowInsecureProtocol true
}
}
configurations {
all*.exclude module: 'spring-boot-starter-logging'
}
dependencies {
....
}
}
build.gradle (api)
plugins {
id 'java-library'
id 'maven-publish'
id 'com.jfrog.artifactory'
}
version "${appVersion}"
artifactory {
contextUrl = artifactory_contextUrl
publish {
contextUrl = artifactory_contextUrl
repository {
repoKey = artifactory_repoKey
username = artifactory_user
password = artifactory_password
}
defaults {
publishConfigs('published')
publishIvy = false
publications("mavenJava")
}
}
}
//jar {
////// archiveName 'admin-api.jar'
////// manifest{
////// attributes ("Fw-Version" : "2.50.00", "${parent.manifestSectionName}")
////// }
////// baseName 'admin-api'
//// archivesBaseName = "$archivesBaseName"
//
// from {
// configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
// }
//}
task sourcesJar(type: Jar, dependsOn: classes) {
// classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
publishing {
publications {
mavenJava(MavenPublication) {
from(components.java)
// artifactId = 'admin-api'
artifact(sourcesJar) {
classifier 'sources'
}
}
}
}
task dist(type: Zip, dependsOn: build) {
classifier = 'buildreport'
from('build/test-results') {
include '*.xml'
into 'tests'
}
from('build/reports/codenarc') {
into 'reports'
}
from('build/docs') {
into 'api'
}
from(sourcesJar) {
into 'source'
}
from('build/libs') {
exclude '*-sources.jar'
into 'bin'
}
}
//artifactoryPublish.dependsOn('clean', 'build', 'groovydoc', 'sourcesJar', 'dist')
//publish.dependsOn(artifactoryPublish)
and the task artifactoryPublish produces:
> Task :admin-api:extractModuleInfo
[pool-7-thread-1] Deploying artifact: http://10.0.0.3:8081/artifactory/libs-release-local/com/example/admin-api/0.0.2-RC3/admin-api-0.0.2-RC3-plain.jar
[pool-7-thread-1] Deploying artifact: http://10.0.0.3:8081/artifactory/libs-release-local/com/example/admin-api/0.0.2-RC3/admin-api-0.0.2-RC3.module
[pool-7-thread-1] Deploying artifact: http://10.0.0.3:8081/artifactory/libs-release-local/com/example/admin-api/0.0.2-RC3/admin-api-0.0.2-RC3.pom
> Task :artifactoryDeploy
Now the issue is that,
the modules, like admin-api builds with the name admin-api-0.0.2-RC3-plain.jar, and the resolution of dependency fails in another project, from which this API needs to be used by reporting following issue:
Could not resolve com.example.admin-api:0.0.2-RC3.
Required by:
project :admin-api
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
gradle dependency statement:
dependencies {
compileOnly('com.example:admin-api:0.0.2-RC3')
}
Please assist me on what is going wrong here.
Also, is their any way so that the modules jar builds without the suffix -plain?
Thanks in advance:)
Hi finally I've achieved this using the following configurations:
allprojects {
....
bootJar {
enabled = false
}
jar {
archiveClassifier.convention('')
archiveClassifier.set('')
}
....
}

JAR from JFrog Artifactory downloading to the Gradle cache but not displaying in Project and External Dependencies

My Java Gradle project is not resolving JARs to the Project and External Dependencies. However, I have checked the Gradle cache location(/Users/Name/.gradle/caches/modules-2/org.jfrog.example.gradle/gradle-example-ci-server/1.0) and it is present there. Below is my build.gradle code. Advise what I am missing here.
apply plugin: 'java'
apply plugin: 'eclipse'
targetCompatibility = 10
sourceCompatibility = 10
eclipse {
classpath {
downloadSources = true
}
}
repositories {
mavenLocal()
maven {
credentials {
username = "${gradleUser}"
password = "${gradlePassword}"
}
url "https://leranartifactory.jfrog.io/artifactory/default-maven-local/"
authentication {
basic(BasicAuthentication)
}
}
dependencies {
compile(group: 'org.jfrog.example.gradle', name: 'gradle-example-ci-server', version: '1.0')
}
}
JFrog Repo Screenshot:
The dependencies clause should not be in the repositories clause. Try to move it out:
repositories {
mavenLocal()
maven {
credentials {
username = "${gradleUser}"
password = "${gradlePassword}"
}
url "https://leranartifactory.jfrog.io/artifactory/default-maven-local/"
authentication {
basic(BasicAuthentication)
}
}
}
dependencies {
compile(group: 'org.jfrog.example.gradle', name: 'gradle-example-ci-server', version: '1.0')
}

Eclipse libGDX project can't resolve gradle dependency of local repo but CLI has no problem?

I'm trying a libgdx project depending on a lib published in local repo with maven-publish:
// to publish locally:
// ~/gdx-gltf$ ./gradlew gltf:publishToMavenLocal
apply plugin: 'maven-publish'
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'io.github.odys-z'
artifactId = 'gdx-gltf'
version = '0.1.0-SNAPSHOT'
from components.java
}
}
}
When I running the depending desktop with gradlew CLI, it's working:
./gradlew desktop:run
But in eclipse and right click the BasicTweenTest class (gradle project.ext.mainClassName) and run as java application, eclipse reported errors:
com.badlogic.gdx.utils.GdxRuntimeException: java.lang.Error: Unresolved compilation problems:
sceneAsset cannot be resolved to a variable
GLTFLoader cannot be resolved to a type
SceneModel cannot be resolved to a type
scenes cannot be resolved or is not a field
animationLoader cannot be resolved to a variable
The missing type is in the local repo dependency, gdx-gltf-0.1.0-SNAPSHOT. No matter what I cleaned projects or refreshed gradle, the error persisting appear.
Eclipse Screenshot with stacktrace report
desktop/build.gradle:
apply plugin: "java"
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/", "test/" ]
sourceSets.main.resources.srcDirs = ["../android/assets", "test"]
// project.ext.mainClassName = "io.oz.wnw.norm.desktop.DesktopLauncher"
// project.ext.mainClassName = "io.oz.wnw.norm.desktop.PlaneStarTest"
project.ext.mainClassName = "io.oz.wnw.norm.desktop.BasicTweenTest"
project.ext.assetsDir = new File("../android/assets")
task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}
task debug(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
debug = true
}
task dist(type: Jar) {
manifest {
attributes 'Main-Class': project.mainClassName
}
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}
dist.dependsOn classes
The other two tests commented out above can run both in CLI and eclipse, which don't depend on the local published package. Any idea?
--------- parent project/build.gradle ----------
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
// jcenter()
google()
}
dependencies {
classpath 'org.wisepersist:gwt-gradle-plugin:1.0.9'
classpath 'com.android.tools.build:gradle:7.0.0-alpha08'
}
}
allprojects {
version = '1.0'
ext {
appName = "wn cloud"
gdxVersion = '1.9.14'
gltfVersion = '0.1.0-SNAPSHOT'
roboVMVersion = '2.3.8'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}
repositories {
mavenLocal()
maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
mavenCentral()
// jcenter()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java-library"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
}
}
project(":html") {
apply plugin: "java-library"
apply plugin: "gwt"
apply plugin: "war"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
api "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
api "com.badlogicgames.ashley:ashley:$ashleyVersion:sources"
}
}
project(":core") {
apply plugin: "java-library"
apply plugin: 'eclipse'
eclipse {
classpath {
downloadSources=true
downloadJavadoc = true
}
}
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.ashley:ashley:$ashleyVersion"
api 'io.github.odys-z:gdx-gltf:0.1.0-SNAPSHOT'
}
}
I faced the same problem. Turns out that LibGDX works with JDK 7 and any version compiled above won't work.
You need to enforce java to compile at version 1.7 before publishing locally
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7

groovy.lang.MissingPropertyException: Could not get unknown property

Caused by: groovy.lang.MissingPropertyException: Could not get unknown
property 'NEXUS_USERNAME' for object of type
org.gradle.api.publication.maven.internal.deployer.DefaultGroovyMavenDeployer.
I do not understand this problem. even though I know his mistake. but I still don't understand how to solve the problem.
this is my Gradle code
apply plugin: 'idea'
apply plugin: 'kotlin'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'org.jetbrains.dokka'
buildscript {
ext.version_kotlin = '1.3.21'
ext.version_dokka = '0.9.17'
ext.version_java_util = '[2.0.1,2.1.0)'
ext.version_slf4j = '[1.7,1.8)'
ext.version_mockito = '[2.8,2.9)'
ext.version_logback = '[1.2,1.3)'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$version_kotlin"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$version_dokka"
}
}
dokka {
outputFormat = 'html'
outputDirectory = "$projectDir/doc/javadoc"
}
version VERSION
group GROUP
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version_kotlin"
api "com.github.michael-rapp:java-util:$version_java_util"
implementation "org.slf4j:slf4j-api:$version_slf4j"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$version_kotlin"
testImplementation "org.mockito:mockito-core:$version_mockito"
testImplementation "ch.qos.logback:logback-classic:$version_logback"
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from tasks.javadoc.destinationDir
}
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
artifacts {
archives jar
archives javadocJar
archives sourcesJar
}
signing {
required { gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION
repository(url: RELEASE_REPOSITORY_URL) {
authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
}
snapshotRepository(url: SNAPSHOT_REPOSITORY_URL) {
authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
}
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}
in the section is red " MavenDeployment "
I take raw materials on GitHub. I want to use this application to be able to use APRIORI logic. if anyone can help please comment below. for more details, I also include the address where I downloaded it Link

Gradle: Unable to initialize POM pom-default.xml: Failed to validate POM

I am getting 'Unable to initialize POM pom-default.xml: Failed to validate POM' when uploading archive using 'uploadArchives'. I tried maven-publish plugin also but still no luck. Any help will be appriciated.
Below is my gradle.build file:
buildscript {
ext {
springBootVersion = '1.2.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE')
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven'
apply plugin: 'signing'
jar {
baseName = 'zmailapp'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-ws')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.lau ncher.StandardVMType/JavaSE-1.8'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.7'
}
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives javadocJar, sourcesJar
}
signing {
sign configurations.archives
}
group = "com.adadyn"
archivesBaseName = "zmailapp"
version = "0.0.1-SNAPSHOT"
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy /maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'ZmailApp'
packaging 'jar'
// optionally artifactId can be defined here
description 'A application used as an example on how to set up pushing its components to the Central Repository.'
url 'http://zmailapp.com'
scm {
connection 'scm:git:https://github.com/zishan2050/ZmailApp'
developerConnection 'scm:git:https://github.com/zishan2050/ZmailApp'
url 'https://github.com/zishan2050/ZmailApp'
}
licenses {
license {
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'manfred'
name 'Manfred Moser'
email 'manfred#sonatype.com'
}
}
}
}
}
}
I solved the above error by adding below code in pom.project{ } block of gradle.build file.
parent {
groupId "org.springframework.boot"
artifactId "spring-boot-starter-parent"
version "${project.bootVersion}"
}

Categories

Resources