How can a Gradle plugin access its own files? - gradle

My custom Gradle plugin contains files which it wants to copy into the output produced by the build that uses my plugin.
How can my plugin access its own files?
All variables I have tried always refer to the project that applied my plugin, but not to the contents of the plugin.

It seems that if files are located in the jar itself it can be loaded via the following construct:
getClass().getResource("resourceName")

Related

Build additional ZIP with only sources

Is there a way in Maven to build additionally to the JAR file a ZIP file with only the sources and some text files in it?
I've tried using the assembly plugin for that but it seems it always includes the JAR in the ZIP file.
You use the Maven Source Plugin for this purpose.
You can use the includes parameter to customise exactly what it should include, such as your additional text files.
Maven Assembly plugin can solve this for you. You can configure as many zip artifacts as you want and add to your build process.

How can i package an eclipse-plugin with maven as a folder?

When i export my eclipse rcp product with eclipse, then it creates my plugin as a folder and everthing works fine. but when i build my product with maven, i can't access images and audio files who are saved in the plugin jar file.
Is it's possible to package a eclipse-plugin as a folder?
Specify:
Eclipse-BundleShape: dir
in the MANIFEST.MF file for the plug-in to say you want a directory (folder) rather than a jar.
Note: If you use a Feature based build the unpack option in the feature.xml will override this.
See also the Eclipse help
Eclipse does also provide APIs to allow you to access files in the plug-in jar (mainly FileLocator).

Maven: generate MANIFEST in custom location

I am trying to retrieve the implementation title and version for a maven jar module. If I use Myclass.class.getPackage().getImplementationVersion() on the built jar, it works, but the same does not work in a debugging environment where the jar is not built, but classes are available.
I am aware of using the Maven JAR plugin to generate the MANIFEST for a maven jar module. So one approach I am considering is to somehow create a copy of the MANIFEST in the generated sources output folder, which I include in my debug classpath. To achieve this:
Is it possible to generate the MANIFEST file in a custom location? If so, what is the plugin and execution configuration necessary?
If not, in which location is the file generated, so I may copy it my custom location using the maven-resources-plugin?
The Manifest file is created dynamically when the archive is assembled. There is no default way to do this.
The easiest I would come up with is to put a MANIFEST.MF in a resource directory, let Maven filter it and add the directory with a profile. This would mimic the way Maven Archiver creates your MANIFEST.MF. The hard way would be to create a custom plugin around Maven Archiver and pass the very same config as to the JAR plugin and enable it with a profile again.

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

include source files in war maven

I want to include source files also in Maven - War file . Some plugins in maven will do that but they are including source files in classes folder. But my requirement is that when I import the same war file again into eclipse I should be able to work on that war like any other normal war.
Basically I should be able to work on the same war after importing it to eclipse when I build maven project. (I'm using maven3. )
I remember that's not trivial because the war-plugin doesn't support the handy includes-configuration-element you know from the jar-plugin by default.
Therefore I suggest you to use the maven-assembly-plugin to configure the inclusion of your sourcefiles. You only need to define an assembly descriptor, where you list includes and excludes of your war-package. Maybe you can reuse one of the predefinied assembly descriptors to save some time.

Resources