Gradle - Copy file inside a dependency of a java project - gradle

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}

Related

Generate dependencies list from list of jar files

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.

Maven multi-module project - copying all dependencies into a single tar.gz

I'm looking to pull all of the dependencies from each module of my maven project and stick them into a single tar.gz file using the maven-assembly-plugin.
I currently have a pom setup as a parent to all of the modules. My idea was to use the maven-dependency-plugin to copy all of the dependencies to a single folder in the parents directory however when i use
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
The dependencies are copied into the modules build directory. Is there any way to set this output directory to one inside the parent project?
You are going at it the wrong way.
Instead of creating this archive inside the parent POM, you should create another module which will be responsible for creating it. This new module will have dependencies on all the other modules.
To create the archive, you need to use the maven-assembly-plugin. I strongly suggest that you read Chapter 8. Maven Assemblies of the Maven book to get you started with using assemblies. Basically, an assembly is created with the help of an assembly descriptor. In your case, you will need to configure this descriptor to use the tar.gz format.

Can I make a Maven plugin that generates a project and then builds that project?

Is it possible to combine the capabilities of an archetype and a normal Maven plugin into a single plugin?
I have a custom language which I can compile into Java source code. I've written a Maven plugin which does this in the generate-sources phase, adds the Java source to the project, and builds the project. It works as I'd expect.
However, to use it, I need to first write out a pom.xml file referencing my plugin and describing where the input files live. I'd like to be able to go straight from raw input files to compiled code in a single maven command.
For example, suppose I have this directory structure:
my-project/
some-input-file.dsl
I want to run
bash$ mvn com.waisbrot.plugin:generate -DgroupID=com.waisbrot package
and after Maven's done running have:
my-project/
some-input-file.dsl
pom.xml
target/
generated-sources/
plugin/
SomeInputFile.java
classes/
com/
waisbrot/
SomeInputFile.class
some-input-file-1.0.jar
Actually, the integration testing of the archetype allows you to declare the parameter and goals. So do this:
Pick the template project you want to create
mvn archetype:create-from-project. It will create a new archetype
Review src/test/resources/projects, especially goal.txt and archetype.properties (source: http://maven.apache.org/archetype/maven-archetype-plugin/integration-test-mojo.html). Tweak so install will be implicity
mvn verify will be able to build the archetype, run the it, and get it installed
Hope it helps

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)

Compiling with gradle idea

Hi) when I compile the project are with gradle idea, I should get jar file...?
maybe in the folder dist...
The problem is that I get only two files start.sh and start.cmd
gradle idea doesn't compile the project. It creates project files (*.iws, *.ipr, *l.iml) for IDEA (the IDE from JetBrains). Likewise, there is gradle eclipse to create project files for the Eclipse IDE.
To create a Jar, you can do gradle jar or gradle build (assuming you have the java plugin applied). gradle tasks shows which tasks are available for a given project.
start.sh and start.cmd sound like they are coming from the application plugin. Are you using the application plugin?
The above poster is right that gradle idea simply creates the IntelliJ files that define your modules, src locations, etc. It does NOT compile the project.
Adding apply plugin: 'java' to your build.gradle will allow you to run gradle jar to generate a jar file.

Resources