Gradle - Add single file to JAR - file

I have the file "license.txt" in the root directory of my project. In the jar-task, I want to add this file to the (root folder of the) JAR file.
I tried
jar {
from '.' include 'license.txt'
}
but this replaces the other content (.class files) instead of adding a file.
And I do not want to add the license.txt to the resources folder, because I do not want to change my project structure just because of the build tool.
Who can help? Thank you!

To add a single file, you can simply do:
jar {
from "license.txt"
}
Your solution should also work if you scoped your include to your from by enclosing it in curly braces.

If you would like to add multiple files, you can do:
jar{
from{
["aaa.txt","bbb.txt"]
}
}

You would add multiple files to output jar as under:
jar {
// Update jar name according to Ascertia conventions
/**
* archiveFileName
* The archive name. If the name has not been explicitly set, the pattern for the name is:
* [archiveBaseName]-[archiveAppendix]-[archiveVersion]-[archiveClassifier].[archiveExtension]
*/
archiveFileName = 'database_postgresql.jar'
from(['build/classes/java/main','mappings/postgresql'])
}
All contents in below directories will be added:
build/classes/java
/main/mappings/postgresql

Related

Gradle renaming file name with wildcards

I have the following task in my build.gradle
task zipConfiguration(type: Zip) {
def myDir = project(':SomeProject').projectDir.toString() + '/build/libs/'
from myDir
archiveName 'Output.zip'
destinationDirectory = file("$buildDir/libs")
}
build/libs of project SomeProject will always have one versioned jar file. For e.g. configuration_2021_06.jar
With every build, the jar created will have a new version number. So the name of the jar I am zipping is dynamic.
However, I want a constant name myconfig.jar to go inside the Output.zip
How can I rename configuration_*.jar to myconfig.jar ?
Tried rename ('*.jar', 'myconfig.jar') : Gives error Dangling meta character '*' near index 0
Tried rename ('configuration*.jar', 'myconfig.jar') : Doesn't rename it. I still see
configuration_2021_06.jar inside Output.zip
The * needs to be like:
rename ('configuration(.*).jar', 'myconfig.jar')

atom package: optionally load snippet file

When creating a language package for atom, it's possible to define a /snippets folder. Any files in here are automatically loaded when the package is active and the context (eg: ".source.js") is opened in the editor.
Now I'd like to contribute to the language-arma-atom package, where there's currently 3 snippet files: I want to add a checkbox option in the package settings to NOT load one of these files.
ie: I know how to add the option, but not how to exclude one of these snippet files.
The way I solved this was create a snippetsAvailable folder, put the files in there (and remove the snippets folder)*.
In your main package file, add to your config schema:
config:
optionalSnippets:
title: "My optional snippets"
description: "Adds optional snippets to autosuggestions"
type: "boolean"
default: true
And in your package's activation do something like this:
activate: ->
#subscriptions = new CompositeDisposable
# etc..
atom.config.observe 'my-package.optionalSnippets', (checked) ->
# For copyNewer, see note below *
copyNewer "my-snippets", "#{__dirname}/snippets", {
cwd: "#{__dirname}/snippetsAvailable"
}
* Note: I used the copyNewer package, because it allows me to remove the /snippets folder, ie: it will automatically create it again. More importantly, it won't overwrite the snippets file on each package activation; Except if you updated your package with new snippets.
Obviously you'll have to write copyNewer = require 'copy-newer' at the top of your main file.
Also, if you choose this method, don't forget to put /settings in .gitignore

Create folder in explicit directory AIR

Like the title says I want to create a folder in a specific directory with Adobe Air.
If I use static methods of File like File.userDirectory works fine but I need to give the choice to select the directory.
I am trying this:
file.addEventListener(Event.SELECT, dirSelected);
file.browseForDirectory("Select a directory");
function dirSelected(e:Event):void {
trace(file.nativePath);
file.resolvePath("new_folder");
file.createDirectory();
}
Nothing happens
"resolvePath: Creates a new File object with a path relative to this File object's path, based on the path parameter (a string)."
So:
var newDir:File = file.resolvePath("new_folder");
newDir.createDirectory();

Deleting content of the folder using VC++

I am using the following code to create a directory using the following code.
TCHAR dir_path[] = TEXT("C:\Users\Temp\abc");
if (!CreateDirectory(dir_path,NULL)) {
}
else
{
//directory already exists
}
I want to add the logic to delete all the content of the folder(Files and folders recursively if any are there) if the folder C:\Users\Temp\abc already exists.
Any idea how I can delete the content of the folder recursively?
Thanks in Advance,
Azeem
I am new to this site. Apologies in advance if I am mistaken anywhere.
Firstly find the entries in the directory:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364418%28v=vs.85%29.aspx
See if they are directory or not:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365740%28v=vs.85%29.aspx
and
http://msdn.microsoft.com/en-us/library/windows/desktop/gg258117%28v=vs.85%29.aspx
If yes, change to it and call the function again http://msdn.microsoft.com/en-us/library/windows/desktop/aa365530%28v=vs.85%29.aspx.
Then delete it: http://msdn.microsoft.com/en-us/library/windows/desktop/aa363915%28v=vs.85%29.aspx

How to get the latest file from a directory using groovy?

I have a directory that contains a list of files. I wanted to get the latest file out of all the contents of the said directory. How will I do that?
I am using this code, but I am not getting the latest file out of it. Please help.
def fileDir = new File("A/B").listFiles().first()
Thanks.
As simple as:
new File( 'A/B' ).listFiles()?.sort { -it.lastModified() }?.head()
(taking the negative lastModified, as we want the newest file first)

Resources