Gradle Plugin not found when using wrapper - gradle

I have a small gradle build which is using a 3rd party plugin it works great while running gradle commands I then added the wrapper task so I could distribute the code and it could be built with non gradle users. When I went to test the gradlew command I can not even run gradlew tasks it fails saying the plugin is missing.
Is there some other configuration that needs to happen?
My wrapper task:
task wrapper(type: Wrapper) {
gradleVersion = '1.0-milestone-2'
jarFile = 'wrapper/wrapper.jar'
}
Full build file: https://github.com/beckje01/Multi-Combobox/blob/master/build.gradle

Based on the documentation of this plugin you got to build it from the source code and put it into the directory lib/plugins of your Gradle distribution. My guess is that's what you did before you switched to the Gradle wrapper. Whenever you use the Gradle wrapper your locally installed distribution is not used anymore. Gradle downloads the distribution and puts it under ~/.gradle/wrapper/dists/gradle-1.0-milestone-2. One way to get this running would be to put the plugin in there as you did before. However, this won't make it running for somebody else that checks out your code and runs the build. This is the whole point of using the Gradle wrapper.
What I would do in your case is to upload the plugin artifact to a central repository and refer to it in your build script. It doesn't look like it would be available on Maven Central though. You can upload it to your GitHub project and refer to it in your build script like this:
buildscript {
repositories {
add(new org.apache.ivy.plugins.resolver.URLResolver()) {
name = 'GitHub'
addArtifactPattern 'http://cloud.github.com/downloads/[organisation]/[module]/[module]-[revision].[ext]'
}
mavenCentral()
}
dependencies {
classpath 'beckje01:jslib:0.5'
classpath 'com.google.javascript:closure-compiler:r706'
}
}

Related

How to run remote debug on local kotlinc

I want to compile some sample kotlin project using local compiler. I clone jetbrains/kotlin project from githib and build it. And now i have local compiler in /dist folder. How i need to configure gradle in sample project to use this local compiler in it and have an ability for remote debugging?
The simplest way is to build the whole toolchain and use it in your test projects.
To do that, run the install Gradle task in the Kotlin project:
./gradlew install
This will publish all of the project's Maven modules to the Maven local repository (~/.m2/repository by default) with the default snapshot version, which is 1.3-SNAPSHOT at the moment.
Then, in your test Gradle project:
If you apply the Gradle plugin using a buildscript block and an apply statement, add the mavenLocal() repository to buildscript { repositories { ... } } and use the snapshot version of the Gradle plugin:
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3-SNAPSHOT")
}
}
If the plugins are applied using the plugins { ... } block, modify the settings.gradle script and add the following:
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
}
and again, use the 1.3-SNAPSHOT version of the Gradle plugin:
plugins {
id("org.jetbrains.kotlin.jvm").version("1.3-SNAPSHOT")
}
In order to be able to debug the compiler, you need to run its process with a debugging agent waiting for a connection. Normally, the compiler is run in a daemon process that is harder to connect to. It's much simpler to run the compiler inside the Gradle process. To do that, you need to set a system property kotlin.compiler.execution.strategy to in-process in the Gradle process (note: this should be not a Gradle project property but a Java system property which can be passed by -Dkey=value or set using System.setProperty(...).
Then run a Gradle build with a command line -Dorg.gradle.debug=true to make Gradle wait for a remote debugger. I would advise for running the test project build from the terminal, not the IDE.
This will look like:
./gradlew compileKotlin -Dorg.gradle.debug=true -Dkotlin.compiler.execution.strategy=in-process
Starting a Gradle Daemon, 1 busy Daemon could not be reused, use --status for details
> Starting Daemon
(at this point, the build seems to hang, but it just waits for the debugger, so proceed below)
In the IDE where you work with the Kotlin project, put some breakpoints in the compiler code and attach the remote debugger to the Gradle process.
Note that, with the Kotlin compiler running inside the Gradle process, the latter may run out of memory sooner. Make sure the Gradle process gets enough heap space.

Is there a way to download a Gradle plugin from the repository to Gradle cache and use it in offline mode?

I am trying to create a copy of a gradle project that will work in --offline mode. I have automated all steps apart from one. I am not able to automatically download plugin jars into gradle cache.
My offline distribution works by specifying the GRADLE_USER_HOME, downloading all dependencies and bundling the whole gradle cache with the project. Unfortunately we are using a few custom plugins. I could of course make an exception for each one of them and include them manually, with some kind of if statement for the offline mode. But it would be great if I could simply download the jars into the cache.
Is there a way to force gradle to download all dependencies, including the plugin dependencies?
This is what I am doing for the rest of the dependencies:
task resolveAllDependencies {
doLast {
configurations.all { it.resolve() }
}
}
It downloads all dependencies to the local cache. But plugins are of course not included in any of the configurations.
It also seems that even if the plugin gets downloaded in the cache, it still fails in offline mode with the following message: Plugin cannot be resolved from https://plugins.gradle.org/api/gradle because Gradle is running in offline mode
Here's a working solution. It's not perfect, because it hard-codes the gradle plugin repository and changes the script. It's also much more verbose than the current way of using plugins.
Instead of the following simple plugin definition:
plugins {
id 'net.researchgate.release' version '2.3.5'
}
It's possible to define both the repository and the dependency manually and then use the plugin this way:
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'net.researchgate:gradle-release:2.3.5'
}
}
apply plugin: 'net.researchgate.release'
This downloads the plugin into the local gradle cache.

Run task before repositories are added and dependencies are resolved

I'm working on compiling python bindings using gradle.
There is a plugin by linkedin that facilitates that.
They also include a project called the pivy-importer that converts python dependencies into an ivy repository.
I've created a gradle plugin that wraps the pivy-importer so that it can run as a python task.
My repositories are declared like this:
repositories {
pyGradlePyPi()
ivy {
name 'pypi-local' //optional, but nice
url "${project.buildDir.path}/pythonIvy"
layout "pattern", {
ivy "[organisation]/[module]/[revision]/[module]-[revision].ivy"
artifact "[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"
m2compatible = true
}
}
}
The problem, however, is that the repositories are being loaded before the plugin executes.
The first task that the python task runs is pinRequirements so I was adding my cusom pythonImporter task before that like this:
pinRequirements.dependsOn pythonImporter
However, even when I do that, the console shows that the pythonImporter task is running before but as soon as it tries to assemble the dependencies, it can't find them even though they do exist in the file system.
If you rerun the task again, however, it passes because the first run added the repository to the file system.
TL;DR
I need a way to run a task before dependencies are looked up under using a project's configured repositories are loaded.
I moved the tasks execution to my buildSrc subproject and made the build task depend upon its execution.
This works because the buildSrc project is always evaluated before the rest of the projects so you can do "before build" logic there.

Add dynamic dependencies via command line

Is it possible to use CLI to add a jar with Gradle plugin (or task) to the build classpath without modifying build.gradle? Can the add JAR be resolved from Maven repository?
Is buildscript { dependencies { classpath }} controllable from CLI? And can I use CLI to make Gradle to resolve the JAR from Maven?
Basically I need to achieve the same situation as with Maven, which allows invoking any plugin by
mvn <plugin-group-id>:<plugin-artifact-id>:<plugin-version>:<plugin-goal>
I'm writing a pair of Maven and Gradle plugins to extract information about projects and their dependencies into JSON file, which can be later processed programatically. The idea is to be able to apply it on a large number of OSS projects and, therefore, without modifying them.
I think I get it now
myinit-script.gradle
if (hasProperty('extraDependencies')) {
def extraDeps = property('extraDependencies').split(',')
allprojects {
buildscript {
dependencies {
classpath extraDeps
}
}
}
}
command line
gradlew --init-script myinit-script.gradle -PextraDependencies=org.foo:bar:1.0,org.foo:baz:1.2 build

gradle combining multiple build script dependecies

gradle multiple build script dependencies
We am in the process from transacting my our build scripts from ant to gradle. The ant build is configured the old way without using ivy and getting the dependencies from a lib folder.
We have a number of custom ant tasks packaged in jar. To run the tasks in that jar we also need some other third parties dependencies from the same lib folder.
Being a complex build we cannot afford to move everything in one go and would rather move one bit at a time as we find some time to do it.
I was able to run those custom ant tasks from the gradle build but I am having problems accessing classes from or tasks jars in my gradle build scripts.
In the build script section we have a class path entry needed for artifactory plugin and I tried to add some more class path entries to make our local libs available.
buildscript {
….
dependencies {
// This dependency below is needed by artifactory plugin which we download
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
}
….
}
I tried lots of combinations but I could not get it to work. What we want is to be able to do something like below:
buildscript {
…
dependencies {
classpath {
["org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1",
fileset(dir: "${antBuildDir}/customTasks", includes: 'myTasks.jar'),
fileset(dir: "${antBuildDir}/lib", includes: '*.jar')]
}
}
…
}
Any idea about how can I address this or any other suggestions if you think I am on the wrong path.
Thank you in advance.
Julian

Resources