Generate dependencies list from list of jar files - gradle

We are planning to move our current project to Gradle. Currently we have all the library jar files stored inside the project.
To list this jar files in Gradle project, is there any way to get the list of existing library jar files in Gradle project, so that we don't have to hand code it.

Related

Gradle - Copy file inside a dependency of a java project

I am new to gradle. I am trying to write a gradle script that copies some scripts inside a dependency of a java project. How can I achieve that? I tried to read documentation to figure out how can specific files be pulled from a dependency but couldn't find anything.
So my projectA -> Depends on projectB:moduleB -> Depends on projectC:moduleC:{Has files that I need to copy in projectA tar}

After creating JAR using "maven-jar-plugin" along with "*.Properties"(files), methods from JAR are failing as "*.properties" path is changed

create JAR from maven project, along with all dependable properties files to reuse methods/class from another maven project.
properties files are located into src/main/resource under folder-> ConfigFolder
When JAR is created the path of ConfigFolder changed and below line of code is failing System.getProperty("user.dir")+/src/test/resource/ConfigFolder/Configfilename.Properties
In maven project - *.Properties is being read by below line of code
new FileInputStream(System.getProperty("user.dir")+/src/test/resource/ConfigFolder/Configfilename.Properties")
When Project is converted into Jar using maven-jar-plugin, the hierarchy of Configfilename.Properties changes hence all my methods are failing.
Before converting JAR Folder Hierarchy
ProjectName(maven project)
|-src/main/java
|-src/test/java
|-src/test/resource
|-ConfigFolder
|-Configfilename.Properties
|-testSuites
|-testng.xml
After converting the into JAR
JARNAME-test.jar
|-ConfigFolder
|-Configfilename.Properties
|-testSuties
|-testng.xml
As you see after converting the jar the hierarchy got changed and new **FileInputStream(System.getProperty("user.dir")+/src/test/resource/ConfigFolder/Config.Properties") **returns null
requirement is to convert first maven project into JAR and use it into second maven project as first maven project contains n number of reusable methods/class project.

How to add a xml a file as dependency using gradle?

I have a project build on gradle and it has a directory src/main/dist/deploy. In deploy folder there is a xml file. This xml file i want to add as a dependency in the jar file which my build.gradle is generating. This jar i am adding in the lib folder of another project that has a dependency on my gradle project. The other project is built using ant. When classes bundled in gradle jar are loaded from ant project they are unable to read that xml file from the gradle jar.
The standard java plugin does not look in src/main/dist/deploy for resources.
You should either move the xml file into java plugin's standard resource folder src/main/resources, or add the dist/deploy folder to your main sourceSet's resource list.

Extract all files from dependency

I'm trying to build a gradle task which extracts all files in a dependency, so that I can modify them using bytecode enhancement and repackage them to a custom jar.
How can I extract those files to my classes folder?
Interesting question. So lets split this up,
If you want the dependencies of a project as a File collection, Look at configurations for Gradle. For example, using the java plugin gives you the configurations, configurations.compile and configurations.runtime. See configurations
You can loop through collections using a each closure
You can see the contents of an archive using the zipTree method Example 1 Reference
You may also unzip an archive with the ant support within gradle, e.g.
ant.unzip(src: war.archivePath, dest: destFile)
You can finally build a custom jar using the Jar task type Jar Task

How to include dependency files in maven assembly

I have a maven project which is configured (via the use of pom.xml and assembly.xml) to package a zip file containing both the compiled webapp (war file) and all files under src/main/folder alongside it whenever we run mvn clean package assembly:single.
This project imports/uses another maven project (which becomes a jar file) and that project in turn also imports/uses a third maven project (again a jar file).
The third project also contains some files inside src/main/folder as well which I'd like to be placed alongside the other files in the zip file whenever I build the main project (the one on top of the chain that becomes a war file).
Is it possible somehow to tell maven to include all files in a specific folder inside all it's dependencies (Or in one specific dependency) alongside in the zip file?
Start here: Maven: The Complete Reference - 8.5. Controlling the Contents of an Assembly
Note that if you deploy a Maven project with assembly:assembly (which you really should configure as a <build> plugin, not use on the command line), the assemblies get "attached" to the project and installed in the repository. You can then reach them using the Maven dependency notation, i.e. mygroup:myartifact:extrafiles:zip
I've found the Assembly descriptor <dependencySets> cumbersome to configure. They really are for the simple case (including the JAR files your application needs at runtime).
Here is the general approach I would take for your desired outcome:
Use Maven Dependency Plugin dependency:copy to download the specific files from the other projects, placing them under a sub-directory of target/
Configure your assembly descriptor to add those downloaded/extracted files to your final assembly artifact.
Alternatively, hack something together using Maven Ant Run Plugin.
You will need to produce an additional assembly from the third project to package up the extra files. Append the assembly id so it produces a package named something like third-1.0.0-extrafiles.zip
Then add this as a dependency of your first project using <type>extrafiles</type> in the dependency descriptor. In the assembly for the first project you'll have to tell it to "unpack" the dependencies of this type (so you don't get a zip in a zip)

Resources