Skip to content
Advertisement

Generate and consume gradle dependency without POM

I am trying to generate the .jar of my Gradle project but when it is generated using Maven publishing it is also generating a .pom file.

The problem is that I have another project that when it implements this dependency before it only looked for .jar and now it looks for .pom in all the others, what I want to do is that the project stops generating a .pom using the “publishing” task or that when implement it stop looking for the .pom files for the others to work.

Here is the code to generate the .jar in Artifactory project A with the one in project B that uses A and looks for the .pom:

publishing {
    publications {
        mavenJava(MavenPublication) {
              groupId = 'com.proteccion.myproject'
              artifactId = 'myproject-base'
              version = '1.0.1'
            from components.java
        }   
    }
    repositories {
        maven {
            name = 'artifactory'
            url 'https://url/artifactory/MyProject'
            credentials {
                username System.getenv("ARTIFACTORY_USER") 
                password System.getenv("ARTIFACTORY_PWD")  
            }
        }
    }
}

repositories {
    jcenter()
    maven {
        url 'https://url/artifactory/MyProject'
        credentials {
                    username System.getenv("ARTIFACTORY_USER") 
                    password System.getenv("ARTIFACTORY_PWD")  
                }
    }
}

Perhaps with a Gradle equivalent of this segment:

publishing {
    publications {
        mavenJava(MavenPublication) {
              groupId = 'com.proteccion.myproject'
              artifactId = 'myproject-base'
              version = '1.0.1'
            from components.java
        }   
    }

Advertisement

Answer

Finally this worked for me:

metadataSources {
            artifact()
        }

Forces to search only for the jar file. The complete configuration:

publishing {
publications {
    mavenJava(MavenPublication) {
          groupId = 'com.company.myproject'
          artifactId = 'myproject-base'
          version = '1.0.1'
        from components.java
    }   
}
repositories {
    maven {
        name = 'artifactory'
        url 'https://url/artifactory/MyProject'
        credentials {
            username System.getenv("ARTIFACTORY_USER") 
            password System.getenv("ARTIFACTORY_PWD")  
        }
    }
}
}

repositories {
jcenter()
maven {
    url 'https://url/artifactory/MyProject'
    credentials {
                username System.getenv("ARTIFACTORY_USER") 
                password System.getenv("ARTIFACTORY_PWD")  
            }
    metadataSources {
            artifact()
    }
}
}

Documentation (Example 18): https://docs.gradle.org/current/userguide/dependency_management.html

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement