How to refer to gradle dependency source.jar - gradle

I want to pass the dependency-x.y.z-sources.jar that gradle downloads as a parameter to another plugin (specifically j2objc )
Is there a way to have a reference to the downloaded source jar?

I assume you are using the gradle j2objc plugin? See here. In short, you need to make sure the gradle compile dependency you add specifies a specific version (no + or unspecified) and that the specified dependency provides a -sources.jar. After that, if you add autoConfigureDeps true to the top of your j2objcConfig closure it will pick up the sources.

Related

How to sort dependencies in a section of a Maven POM file

I need to sort the dependencies in the dependencyManagement section of a POM file that is used as a parent for all projects of my team's portfolio.
The motivation for this is similar to the one described here. In my case, I am just trying to harmonize the versions used throughout our portfolio, in order to avoid the recurring nightmare of version discrepancy: due to copy-paste, some projects use a version of a dependency while others use another version. Another motivation is to have only one place where to manage dependencies. What I am doing is essentially merging dependency specifications from all modules into a giant dependencyManagement section of a parent POM. (EDIT: In the process of looking for an answer to this need of mine, I learned that such a POM is what Maven calls a BOM or "bill of materials".)
However, this task requires that I define the version of each dependency in our parent POM. Doing so, I find myself putting the dependency specification somewhere in what is a growing list of dependencies. It gets more and more difficult to add a dependency and find out whether the dependency is already specified. But that would be much easier if I could sort the dependencies, for instance by group ID.
Is there a plugin that serves that purpose of reordering the dependencies? As a last resort, I will end up writing a small program that will read the XML file from the parent POM and output it sorted.
The recently released version 0.2.0 of BOM Helper Maven Plugin now has the sort goal that does exactly that.
You need to add the plugin to your pom:
<plugin>
<groupId>com.commsen.maven</groupId>
<artifactId>bom-helper-maven-plugin</artifactId>
<version>0.2.0</version>
</plugin>
You can configure it to run on every build, but I would rather run it manually only when I add/change a dependency. Something like:
mvn bom-helper:sort -Dbom-helper.inplace=true
should do the job. See the docs for more options.
I used sortpom. See more about parameters at https://github.com/Ekryd/sortpom/wiki/Parameters
mvn com.github.ekryd.sortpom:sortpom-maven-plugin:sort -Dsort.encoding=UTF-8 -Dsort.sortDependencies=scope,groupId,artifactId -Dsort.sortPlugins=groupId,artifactId -Dsort.sortProperties=true -Dsort.sortExecutions=true -Dsort.sortDependencyExclusions=groupId,artifactId -Dsort.lineSeparator="\n" -Dsort.ignoreLineSeparators="false" -Dsort.expandEmptyElements=false -Dsort.nrOfIndentSpace=2 -Dsort.indentSchemaLocation=true
The easiest way to sort your dependencies is to use the sortpom maven plugin.
It is very easy to use. Just go to your project directory, open terminal and run the following command:
mvn com.github.ekryd.sortpom:sortpom-maven-plugin:sort -Dsort.keepBlankLines -Dsort.predefinedSortOrder=custom_1
To find more about the project, check their github repo: https://github.com/Ekryd/sortpom

Using JGitVer in a tycho pomless build

I would like to use the jgitver maven plugin to automatic define the version of eclipse plugins, features, repository that are built with tycho in pomless mode.
The version management of this 3 plugins are:
jgitver computes a version depending on git tree and tags, create a logical copy of pom, set the new version and associate the new pom to the current plugin in the maven reactor.
For tycho, version are defined in pom and in manifest.mf or feature.xml files. A version consistency check is performed.
When the pom is not defined, pomless maven generates a temporary pom file named .polyglot.build.properties using versions defined in manifest or feature file.
The input path are defined here and depends on PolyglotModelUtil.
The easier way would be a Jgitver evolution to locally update the feature.xml and manifest.MF. It would be a bad idea because a local file would be modified that is not compliant with the plugin philosophy.
A better way would be a Jgitver evolution to generate temporary feature.xml and manifest.MF files that would have been updated with the computed version. Then tycho and tycho-pomless should be forced to use them.
It seems to be possible if i succeed in setting a new ModelProcessor.LOCATION option
Do you think it's an effective way to solve this compatibility problem?
Do you see an alternative?
Thanks for your help.
You could also use directly the jgitver library to participate into your build environment ; it is a pure java library.
The library is the base of both the maven and gradle plugins.

How can I make Gradle download optional dependencies automatically?

When downloading dependencies using Gradle it seems to exclude optional dependencies. For example, I included Guava:
compile 'com.google.guava:guava:19.0'
and it did not download the optional dependencies listed here: https://mvnrepository.com/artifact/com.google.guava/guava/19.0
I've been learning Gradle and porting a legacy app to use Gradle. That application had a Python script wrapper that always downloaded the optional dependencies and I've kind of hit a wall here.
According to the description of the Maven's Optional Dependencies:
If a user wants to use functionality related to an optional dependency, they will have to redeclare that optional dependency in their own project.
Gradle has the same behavior as Maven, if you want to use some transitive optional dependencies - you have to declare them manually.
You can try to find some workaround, but anyway, it seems to be a little odd, to include all optional dependencies by default, don't even check, whether are they really needed. Sure, you can try to port your logic to run existent Python script with Gradle to collect all optional dependencies into local directory and declare it as file dependencies.

Maven Assembly Plugin: Unpacking overwrites different versions of dependencies

I am using Maven assembly plugin with which I generate single Jar file with all dependencies for my application (unpacked by definition in jarlib.xml given here: https://gist.github.com/knyttl/7cc0730ae0fb6947cbda). This dependency.jar can be then put on class path with my application.jar and run as java -cp application.jar:dependencies.jar my.class.Runner. The problem are however multiple versions of the same artifacts when unpacking jars.
For instance I am using org.apache.xmlrpc:xmlrpc-server:jar:3.1.3 which depends on javax.servlet:servlet-api:jar:2.3. In my application I need to use different, newer version of the javax.servlet, but when unpacking, the new version is skipped and the old one is used instead.
Is there a way to ignore the dependency given by xmlrpc-server?
Is there a way to prioritize the newer version of javax.servlet?
Is there a way to create single jar without unpacking the dependencies and being able to use them with -cp application.jar:dependencies.jar? When I tried to build the jar without unpacking, none of the inner jar classes were found when running the application.
Sounds like what you really want is the shade plugin - the ability to create a single jar with all of these included. https://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html
The best solution I found is using <exclusions> directly in the <dependency> tag directly in the pom, without any plugins.

How can I get list of plugin dependencies?

It is said that:
Maven 2.0.9 introduced the ability to override a dependency used by a
plugin. This is handy when you want to use a newer checkstyle, pmd,
etc jar than is included by default in the plugin.
My question is - how can I get list of dependencies of some specific plugin just as easy as I can get list of dependencies of the project?
Executing mvn dependency:resolve-plugins will provide a list of all the plugins defined within your POM (and those inherited from any parent POMs) along with all the dependencies of each plugin.

Resources