Gradle mavenDeployer - how to include a separate modules code - java

I have a project like this:
MyProject
|-ModuleA
|-ModuleB
Module A is an Android Library that creates an aar, it has a dependency on Module B like so:
dependencies {
compile project(':ModuleB')
In ModuleA I am using mavenDepoyer to release locally:
uploadArchives {
repositories.mavenDeployer {
pom.groupId = "com.foo"
pom.artifactId = "bar"
pom.version = "1.0"
repository(url: "file://${localReleaseDest}")
}
}
This generates me an AAR file and a POM.
When uncompressed the AAR does not contain the class files from Module B
and the POM looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>MyProject</groupId>
<artifactId>ModuleB</artifactId>
<version>unspecified</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
As you can see this declares that the AAR has a dependency on ModuleB with an unspecified version. And so if I use this this AAR/POM as a remote, it fails to resolve the dependency ModuleB.
Error:A problem occurred configuring project ':example'.
Could not resolve all dependencies for configuration ':example:_debugCompile'.
Could not find MyProject:ModuleB:unspecified.
Searched in the following locations:
https://jcenter.bintray.com/MyProject/ModuleB/unspecified/ModuleB-unspecified.pom
https://jcenter.bintray.com/MyProject/ModuleB/unspecified/ModuleB-unspecified.jar
Required by:
Test:example:unspecified > com.foo:MyProject:1.0
I do not want it to try and resolve Module B as another dependency, I want to use the mavenDeployer to be able to create the AAR & POM with Module B included inside, since I have the source code here to do that!
Searched the web to no avail, these sites gave hints but no answer:
How to publish apks to the Maven Central with gradle?
how to tell gradle to build and upload archives of dependent projects to local maven
http://www.gradle.org/docs/current/userguide/artifact_management.html
http://gradle.org/docs/current/userguide/userguide_single.html#sub:multiple_artifacts_per_project
http://gradle.org/docs/current/userguide/userguide_single.html#deployerConfig

As far as I know, AARs don't include their dependencies (only APKs do). Instead, transitive dependency resolution will take care of resolving not only the AAR but also its dependencies. The unspecified version is most likely a result of not setting the project.version property in ModuleB.

<dependency>
<groupId>MyProject</groupId>
<artifactId>ModuleB</artifactId>
<version>unspecified</version>
<scope>compile</scope>
</dependency>
The reason is your module dependencies is below :
compile project(':module B')
to resolve this issue, you should dependens maven dep
compile 'com.xxxxxx.xxx:xxxxx:1.0.0-SHNAPSHOT'

Related

how to handle maven internal dependancies?

Could someone let me know easy way to handle internal dependencies for maven projects. For now I have following things.
MainPorject depends on project A, B and C - Fat jar
Project A needs project B for compilation - Thin Jar
and project b depends on project c on compilation - Thin Jar
for now, I manually compile all the jar files from A,B and C project from their respective repos and put in mainProject to crate fat jar.
Is there a way I can provide config in such a way that when I compile mainProject it automatically fetches the latest code A,B and C repo? Same goes for project A and Project B.
Build a multi-module project that contains all three projects as modules. Then you always build everything with the latest code. And Maven takes care that everything is built in the right order.
You need a multi-module Maven project, with this setup:
<!-- parent -->
<groupId>com.stackoverflow</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<modules>
<module>C</module>
<module>B</module>
<module>A</module>
<module>Bundle</module>
</modules>
<!-- each module, optionally, if you want to let parent manage the dependency versions -->
<parent>
<groupId>com.stackoverflow</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
Parent pom.xml sits in a root directory and A, B, C, Bundle are direct children of the root directory.
<root>
| pom.xml
|
+---A
| pom.xml
|
+---B
| pom.xml
|
+---Bundle
| pom.xml
|
\---C
pom.xml

Gradle include transitive dependencies in directory

I have a java project which has a couple of dependencies, e.g.:
dependencies {
compile("com.whatever.jar:jar-1:1.2.3")
compile("com.whatever.jar:jar-2:4.5.6")
compile("com.whatever.jar:jar-3:7.8.9")
}
I package it as a jar library and publish it to the repository together with a POM file that describes those dependencies:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.project</groupId>
<artifactId>my-library</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.whatever.jar</groupId>
<artifactId>jar-1</artifactId>
<version>1.2.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.whatever.jar</groupId>
<artifactId>jar-2</artifactId>
<version>4.5.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.whatever.jar</groupId>
<artifactId>jar-3</artifactId>
<version>7.8.9</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
I also have another project which depends on this previously built jar on compile time:
dependencies {
compileOnly("com.my.project:my-library:1.0.0")
}
I would like to create a task that builds the second project and creates a zip file containing both com.my.project:my-library:1.0.0 jar and its transitive dependencies (jar-1, jar-2 and jar-3).
task createZip << {
into('lib') {
// here I would like to do something like (it's a horrible pseudo-code):
from configurations.(com.my.project:my-library:1.0.0).jar.transitiveDependencies.files
}
}
How do I achieve that?
Edit: I also would like to access the list of my-library's transitive dependencies (and precisely those, not any other dependencies in the project) programmatically in order to build a Loader-Path manifest attribute using those.
Here’s a self-contained build.gradle script which demonstrates how your createZip task (which only adds specific dependencies to the ZIP archive) can be created:
/* make the "compileOnly" configuration available */
plugins {
id 'java'
}
/* add some demo dependencies to the project */
repositories {
jcenter()
}
dependencies {
compileOnly 'junit:junit:4.12'
compileOnly 'org.slf4j:slf4j-simple:1.7.28'
}
task createZip(type: Zip) {
// the "lib" directory in the ZIP file will only have all those dependency
// files of the "compileOnly" configuration which belong to the
// "junit:junit:4.12" module:
def depOfInterest = dependencies.create('junit:junit:4.12')
into('lib') {
from configurations.compileOnly.resolvedConfiguration.getFiles({dep ->
dep == depOfInterest
})
}
// the "justForDemonstration" directory in the ZIP file will have all
// dependency files of the "compileOnly" configuration, incl. SLF4J:
into('justForDemonstration') {
from configurations.compileOnly
}
}
This can be run with ./gradlew createZip (tested with Gradle 5.6.2). It produces the ZIP file under build/distributions/<your_project_name>.zip. Let me know if that’s what you had in mind with your pseudocode.
task uberJar(type: Jar) {
dependsOn classes
from sourceSets.main.runtimeClasspath.collect { it.directory?fileTree(it):zipTree(it)}
classifier = 'uber-jar'
}
assemble.dependsOn uberJar

Maven: How to use a build.gradle file?

I'm a complete beginner with both Maven and Gradle. I have a working Maven project. Now I want to add a bunch of classes from another project which was built using Gradle. I want to take classes from the Gradle project and use it in my Maven project. When I copy the classes into my Maven project, I get a bunch of dependency errors. To resolve those errors I would like to add the required stuff to my pom.xml file.
Basically, I want to add all dependencies specified in a build.gradle file, to my pom.xml file.
The pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myGroupId</groupId>
<artifactId>myArtifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.jgrapht/jgrapht-core -->
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>1.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jgrapht/jgrapht-jdk1.5 -->
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-jdk1.5</artifactId>
<version>0.7.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jgrapht/jgrapht-ext -->
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-ext</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.0-jre</version>
<!-- or, for Android: -->
<!-- <version>27.0-android</version> -->
</dependency>
<!-- https://mvnrepository.com/artifact/net.sf.trove4j/trove4j -->
<dependency>
<groupId>net.sf.trove4j</groupId>
<artifactId>trove4j</artifactId>
<version>3.0.3</version>
</dependency>
</dependencies>
</project>
The build.gradle file:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.rapidminer.com/content/groups/public/' }
}
}
plugins { id 'com.rapidminer.extension' version '0.8.2' }
// Define Maven artifact repositories
repositories {
jcenter()
maven { url 'https://maven.rapidminer.com/content/groups/public/' }
ivy {
url "https://github.com/rapidprom/rapidprom-libraries/raw/${project.properties["version"]}/prom/"
layout "pattern", {
artifact "[module]-[revision]/[module]-[revision].[ext]"
artifact "[module]-[revision]/[artifact].[ext]"
ivy "[module]-[revision]/ivy-[module]-[revision].xml"
}
}
ivy {
url "https://github.com/rapidprom/rapidprom-libraries/raw/${project.properties["version"]}/thirdparty/lib/"
layout "pattern", {
artifact "[module]-[revision]/[module]-[revision].[ext]"
ivy "[module]-[revision]/ivy-[module]-[revision].xml"
}
}
ivy {
url "https://github.com/rapidprom/rapidprom-libraries/raw/${project.properties["version"]}/thirdparty/resource/"
layout "pattern", {
artifact "[module]-[revision]/[module]-[revision].[ext]"
ivy "[module]-[revision]/ivy-[module]-[revision].xml"
}
}
}
extensionConfig {
// The extension name
name 'RapidProM'
/*
* The artifact group which will be used when publishing the extensions Jar
* and for package customization when initializing the project repository.
*
*/
groupId = 'org.rapidprom'
/*
* The extension vendor which will be displayed in the extensions about box
* and for customizing the license headers when initializing the project repository.
*
*/
vendor = "Eindhoven University of Technology"
/*
* The vendor homepage which will be displayed in the extensions about box
* and for customizing the license headers when initializing the project repository.
*
*/
homepage = "www.rapidprom.org"
// enable shadowJar before rapidminer dependency (otherwise build fails)
shadowJar {
zip64 true
}
// define RapidMiner version and extension dependencies
dependencies {
rapidminer '7.2.0'
//extension namespace: 'text', version: '7.2.0'
}
}
// Define third party library dependencies
dependencies {
compile group:"org.rapidprom", name:"ProM-Framework", version:"31245"
compile "org.rapidprom:AcceptingPetriNet:6.7.93"
compile "org.rapidprom:AlphaMiner:6.5.47"
compile "org.rapidprom:Animation:6.5.50"
compile "org.rapidprom:ApacheUtils:6.7.88"
compile "org.rapidprom:BasicUtils:6.7.104"
compile "org.rapidprom:BPMN:6.5.56"
compile "org.rapidprom:BPMNConversions:6.5.48"
compile "org.rapidprom:CPNet:6.5.84"
compile "org.rapidprom:DataAwareReplayer:6.7.563"
compile "org.rapidprom:DataPetriNets:6.5.291"
compile "org.rapidprom:DottedChart:6.5.17"
compile "org.rapidprom:EvolutionaryTreeMiner:6.7.154"
compile "org.rapidprom:EventStream:6.5.72"
compile "org.rapidprom:FeaturePrediction:6.5.61"
compile "org.rapidprom:Fuzzy:6.5.33"
compile "org.rapidprom:GraphViz:6.7.185"
compile "org.rapidprom:GuideTreeMiner:6.5.18"
compile "org.rapidprom:HeuristicsMiner:6.5.49"
compile "org.rapidprom:HybridILPMiner:6.7.116"
compile "org.rapidprom:InductiveMiner:6.7.297"
compile "org.rapidprom:InductiveVisualMiner:6.7.413"
compile "org.rapidprom:Log:6.7.293"
compile "org.rapidprom:LogDialog:6.5.42"
compile "org.rapidprom:LogProjection:6.5.38"
compile "org.rapidprom:ModelRepair:6.5.12"
compile "org.rapidprom:Murata:6.5.54"
compile "org.rapidprom:PetriNets:6.7.95"
compile "org.rapidprom:PNetAlignmentAnalysis:6.5.35"
compile "org.rapidprom:PNAnalysis:6.7.122"
compile "org.rapidprom:PNetReplayer:6.7.99"
compile "org.rapidprom:PTConversions:6.5.3"
compile "org.rapidprom:PomPomView:6.5.36"
compile "org.rapidprom:SocialNetwork:6.5.35"
compile "org.rapidprom:StreamAlphaMiner:6.5.15"
compile "org.rapidprom:StreamAnalysis:6.5.38"
compile "org.rapidprom:StreamInductiveMiner:6.5.42"
compile "org.rapidprom:TransitionSystems:6.7.71"
compile "org.rapidprom:TSPetriNet:6.5.35"
compile "org.rapidprom:Uma:6.5.46"
compile "org.rapidprom:Woflan:6.7.59"
compile "org.rapidprom:XESLite:6.7.217"
compile "org.rapidprom:Weka:6.7.3"
}
To deploy to Maven, use the maven plugin.
apply plugin: 'maven'
group = 'com.company'
version = '1.0.0.6'
// To build and push development snapshots, add a suffix to the name
// version = '1.0.0.6-SNAPSHOT'
artifacts {
archives jar
}
uploadArchives {
repositories {
mavenDeployer {
snapshotRepository(url: 'https://maven.repo/bla') {
authentication(userName: snapshotUser, password: snapshotPassword)
}
repository(url: 'https://maven.repo/bla') {
authentication(userName: releaseUser, password: releasePassword);
}
}
}
}
You can both install to a remote repository by running the uploadArchives task, (example above is https://maven.repo/bla), or install to ~/.m2/repository which is maven local using the install task.
gradle install uploadArchives
If you choose to install to maven local, you can add a dependency on maven local to other gradle projects by using dependencies { mavenLocal() }, or including it in your pom.xml
<settings <!-- bla --> >
<localRepository>${user.home}/.m2/repository</localRepository>
</settings>

Dependency error in eclipse project making use of Maven

I am using Eclipse Mars to run my Java project. I am making use of Maven in it. But while trying to compile my package I am getting the following error.
Failed to execute goal on project apex-check: Could not resolve dependencies for project org.fundacionjala.enforce.sonarqube:apex-check:jar:1.0: Failed to collect dependencies at org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0: Failed to read artifact descriptor for org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0: Could not transfer artifact org.fundacionjala.enforce.sonarqube:apex-squid:pom:1.0 from/to central (https://repo.maven.apache.org/maven2): Failed to authenticate with proxy -> [Help 1].
I am able to find that my pom.xml has a bug in its dependency. But don't know how to resolve it. I have given below my pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!-- ~ Copyright (c) Fundacion Jala. All rights reserved. ~ Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.fundacionjala.enforce.sonarqube</groupId>
<artifactId>apex</artifactId>
<version>1.0b${build.number}</version>
</parent>
<artifactId>apex-check</artifactId>
<name>Apex :: Checks</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apex-squid</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
I have written 'apex-check' and 'apex-squid' as two separate projects.
Can anyone explain how to correct my pom.xml?
You need to have:
org.fundacionjala.enforce.sonarqube:apex-check:jar:1.0
org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0
jar files available in your local .m2/repository folder. If they are not present maven will try to download from central repository and as an expected result it will fail on firewall or it will not find the artifact. i.e. if:
apex-check requires apex-squid project as dependency first you need to install squid project files by using mvn install on squid project folder.
But it seems more like you want to create a multi module maven project, take a look at this question. Create a parent project similar to this project, add check and squid as module and run mvn clean install on parent.
**edit: I just see you already have parent, so make sure parent has your projects as modules, which helps reactive build order and eclipse imports

Ivy not resolving transitive dependencies from public maven repos

Considering the following ivy dependencies,
<dependency org="org.fusesource.restygwt" name="restygwt" rev="1.3"
conf="gwtcompile->default; compile->default"/>
<dependency org="org.jboss.resteasy" name="resteasy-jaxrs" rev="2.3.4.Final"
conf="compile->compile(*),runtime(*);runtime->runtime(*)"/>
They depend on public maven repos mirrored by
http ://myivyserver:8888/mirrored/ .
as specified by the ivysettings resolver chaining to ...
<url name="mirrored" m2compatible="true">
<artifact
pattern="http://myivyserver:8888/mirrored/${maven2.artifact.pattern}" />
</url>
Where I can see the mirrored directory completely replicating the artefacts of remote maven repos.
I am used to Maven and the seeing the buildpath on eclipse showing maven dependencies.
Now, I am creating Ivy-dependency for a project. I am expecting to see similar, and I do see, a similar Ivy dependency node showing all the jars due to the Ivy eclipse pluggin.
However, the Ivy dependency node in eclipse buildpath does not show any jars transitively specified by the mirrored poms.
For example,
<dependency org="org.fusesource.restygwt" name="restygwt" rev="1.3"
conf="gwtcompile->default; compile->default"/>
<dependency org="org.jboss.resteasy" name="resteasy-jaxrs" rev="2.3.4.Final"
conf="compile->compile(*),runtime(*);runtime->runtime(*)"/>
both dependencies’ pom specify dependency on javax.ws.rs (jsr311-api)
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
However javax.ws.rs(jsr311-api) does not show up on the buildpath library of the ivy managed project, as a Maven managed one would.
What further more would I have to do to get ivy plugin to resolve transitive dependencies that are due to maven poms?
Thank you.
URL resolver considers maven layout but not pom dependencies. When I was implementing this functionality ibiblio resolver was able to resolve pom's dependencies.
http://ant.apache.org/ivy/history/latest-milestone/resolver/ibiblio.html
<ibiblio name="maven2" m2compatible="true" root="http://myivyserver:8888/mirrored">
I haven't used it long because I preferred non-transitive dependencies in my code so I've finished with using pure url resolver.

Categories