Reputation: 4609
In Maven is super easy; just add one line
<attachClasses>true</attachClasses>
and two artifacts goes to repository (doc)
My build.gradle is:
group = 'org.gradle.sample'
version = '1.0'
apply plugin: 'war'
apply plugin: 'maven-publish'
jar.enabled = true
jar.classifier = 'classes'
repositories {
mavenLocal()
}
publishing {
publications {
p1(MavenPublication) {
from components.java
}
p2(MavenPublication) {
from components.web
}
}
}
dependencies {
compile 'org.hibernate:hibernate-core:3.6.7.Final'
}
Command: gradle jar publishToMavenLocal
Similar to Maven, 2 artifacts goes to repository (publish-1.0.war and publish-1.0-classes.jar) Moreover, publish-1.0.pom goes to repository but without dependencies. Finally, dependency to Hibernate is lost
For example, I created other Maven project which depends on publish
<dependency>
<groupId>org.gradle.sample</groupId>
<artifactId>publish</artifactId>
<version>1.0</version>
<classifier>classes</classifier>
</dependency>
but there is no dependency to hibernate:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ my-app ---
[INFO] com.mycompany.app:my-app:jar:1.0-SNAPSHOT
[INFO] - org.gradle.sample:publish:jar:classes:1.0:compile
[INFO] (I expect hibernate with it's dependencies but there is not)
Why Gradle is not as smart as Maven is?
Upvotes: 2
Views: 2082
Reputation: 4609
I found pitiful solution: swap publishing order
publishing {
publications {
p1(MavenPublication) {
from components.web
}
p2(MavenPublication) {
from components.java
}
}
}
Upvotes: 1