diff --git a/.gitignore b/.gitignore
index c2d3c1f1..a2b7f14f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,8 @@
*.ipr
*.iws
target/
+/jsign-gradle-plugin/.gradle
+/jsign-gradle-plugin/build
# eclipse files
/.settings
diff --git a/README.md b/README.md
index dfd70fa3..f0d09798 100644
--- a/README.md
+++ b/README.md
@@ -37,7 +37,7 @@ Version 1.4 (in development)
* Fixed the Accept header for RFC 3161 requests (contributed by Markus Kilås)
* Internal refactoring to share the code between the Ant task and the CLI tool (contributed by Michael Peterson)
* The code has been split into distinct modules (core, ant, cli).
-* Jsign is now available as a Maven plugin (net.jsign:jsign-maven-plugin)
+* Jsign is now available as a plugin for Maven (net.jsign:jsign-maven-plugin) and Gradle
* The API can be used to sign in-memory files using a SeekableByteChannel
Version 1.3, 2016-08-04
diff --git a/jsign-gradle-plugin/build.gradle b/jsign-gradle-plugin/build.gradle
new file mode 100644
index 00000000..089849a5
--- /dev/null
+++ b/jsign-gradle-plugin/build.gradle
@@ -0,0 +1,38 @@
+buildscript {
+ repositories {
+ maven {
+ url "https://plugins.gradle.org/m2/"
+ }
+ }
+ dependencies {
+ classpath "com.gradle.publish:plugin-publish-plugin:0.9.7"
+ }
+}
+
+apply plugin: "java"
+apply plugin: "com.gradle.plugin-publish"
+
+repositories {
+ mavenLocal()
+}
+
+dependencies {
+ compile gradleApi()
+ compile 'net.jsign:jsign-core:1.4-SNAPSHOT'
+}
+
+pluginBundle {
+ website = 'https://ebourg.github.io/jsign/'
+ vcsUrl = 'https://github.com/ebourg/jsign'
+
+ description = 'Code signing for Windows executables'
+
+ plugins {
+ jsignPlugin {
+ id = 'net.jsign'
+ displayName = 'Gradle Jsign plugin'
+ tags = ['signing']
+ version = '1.4-SNAPSHOT'
+ }
+ }
+}
diff --git a/jsign-gradle-plugin/example.gradle b/jsign-gradle-plugin/example.gradle
new file mode 100644
index 00000000..d8a3a73a
--- /dev/null
+++ b/jsign-gradle-plugin/example.gradle
@@ -0,0 +1,21 @@
+buildscript {
+ repositories {
+ mavenLocal()
+ }
+
+ dependencies {
+ classpath 'net.jsign:jsign-gradle-plugin:1.4-SNAPSHOT'
+ }
+}
+
+apply plugin: 'net.jsign'
+
+task sign << {
+ signexe(file : 'application.exe',
+ name : 'My Application',
+ url : 'http://www.example.com',
+ keystore : 'keystore.p12',
+ alias : 'test',
+ storepass : 'secret',
+ tsaurl : 'http://timestamp.comodoca.com/authenticode')
+}
diff --git a/jsign-gradle-plugin/pom.xml b/jsign-gradle-plugin/pom.xml
new file mode 100644
index 00000000..df14208e
--- /dev/null
+++ b/jsign-gradle-plugin/pom.xml
@@ -0,0 +1,69 @@
+
+
+ 4.0.0
+ net.jsign
+ jsign-gradle-plugin
+
+ net.jsign
+ jsign-parent
+ 1.4-SNAPSHOT
+ ../pom.xml
+
+ Jsign - Code signing for Windows executables (Gradle Plugin)
+ 1.4-SNAPSHOT
+ jar
+
+ 2017
+
+
+ Pure Java implementation of Microsoft Authenticode for signing Windows executable files
+
+ http://ebourg.github.com/jsign
+
+
+
+ The Apache License, Version 2.0
+ http://www.apache.org/licenses/LICENSE-2.0.txt
+
+
+
+
+
+ gradle-repository
+ http://repo.gradle.org/gradle/libs-releases-local
+
+ true
+
+
+ false
+
+
+
+
+
+ 3.4
+
+
+
+
+ net.jsign
+ jsign-core
+ ${project.version}
+
+
+
+ org.codehaus.groovy
+ groovy-all
+ 2.4.7
+ provided
+
+
+
+ org.gradle
+ gradle-core
+ ${gradle.version}
+ provided
+
+
+
+
diff --git a/jsign-gradle-plugin/src/main/java/net/jsign/GradleConsole.java b/jsign-gradle-plugin/src/main/java/net/jsign/GradleConsole.java
new file mode 100644
index 00000000..a20c1425
--- /dev/null
+++ b/jsign-gradle-plugin/src/main/java/net/jsign/GradleConsole.java
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2017 Emmanuel Bourg
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.jsign;
+
+import org.gradle.api.logging.LogLevel;
+import org.gradle.api.logging.Logger;
+
+/**
+ * Console implementation for Gradle.
+ *
+ * @author Emmanuel Bourg
+ * @since 1.4
+ */
+public class GradleConsole implements Console {
+
+ private final Logger log;
+
+ public GradleConsole(Logger log) {
+ this.log = log;
+ }
+
+ @Override
+ public void debug(String message) {
+ log.debug(message);
+ }
+
+ @Override
+ public void info(String message) {
+ log.info(message);
+ }
+
+ @Override
+ public void warn(String message) {
+ warn(message, null);
+ }
+
+ @Override
+ public void warn(String message, Throwable t) {
+ log.log(LogLevel.WARN, message, t);
+ }
+}
diff --git a/jsign-gradle-plugin/src/main/java/net/jsign/PESignerGradlePlugin.java b/jsign-gradle-plugin/src/main/java/net/jsign/PESignerGradlePlugin.java
new file mode 100644
index 00000000..d0f7be60
--- /dev/null
+++ b/jsign-gradle-plugin/src/main/java/net/jsign/PESignerGradlePlugin.java
@@ -0,0 +1,49 @@
+/**
+ * Copyright 2017 Emmanuel Bourg
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.jsign;
+
+import java.io.File;
+import java.util.Map;
+
+import groovy.lang.Closure;
+import org.gradle.api.Plugin;
+import org.gradle.api.Project;
+
+/**
+ * Gradle plugin registering the signexe extension method with the project.
+ *
+ * @author Emmanuel Bourg
+ * @since 1.4
+ */
+public class PESignerGradlePlugin implements Plugin {
+
+ @Override
+ public void apply(final Project project) {
+ project.getExtensions().add("signexe", new Closure(null) {
+ public void doCall(Map params) throws SignerException {
+ String file = params.get("file");
+ params.remove("file");
+
+ PESignerHelper helper = new PESignerHelper(new GradleConsole(project.getLogger()), "property");
+ for (Map.Entry param : params.entrySet()) {
+ helper.param(param.getKey(), param.getValue());
+ }
+ helper.sign(new File(file));
+ }
+ });
+ }
+}
diff --git a/jsign-gradle-plugin/src/main/resources/META-INF/gradle-plugins/net.jsign.properties b/jsign-gradle-plugin/src/main/resources/META-INF/gradle-plugins/net.jsign.properties
new file mode 100644
index 00000000..75d4aa65
--- /dev/null
+++ b/jsign-gradle-plugin/src/main/resources/META-INF/gradle-plugins/net.jsign.properties
@@ -0,0 +1 @@
+implementation-class=net.jsign.PESignerGradlePlugin
diff --git a/pom.xml b/pom.xml
index 98176358..8ba9bbb0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -57,6 +57,7 @@
jsign-cli
jsign
jsign-maven-plugin
+ jsign-gradle-plugin