gradle buildscripts and Heroku - heroku

If i'd like to use a Steve Saliman's gradle-cobertura-plugin inside my gradle build. Will I need to use a custom buildpack to deploy to Heroku.com? I receive the following error when Heroku tries to run my build. Note, that the very same build works great when I run it locally.
Repository git#heroku.com:myproject.git
pre-receive hook declined
Fetching repository, done.
-----> Gradle app detected
-----> Installing OpenJDK 1.7... done
-----> Building Gradle app...
WARNING: The Gradle buildpack is currently in Beta.
-----> executing gradle -I /app/tmp/buildpacks/gradle/opt/init.gradle stage
Download http://repo1.maven.org/maven2/net/saliman/gradle-cobertura- plugin/2.2.2/gradle-cobertura-plugin-2.2.2.pom
Download http://repo1.maven.org/maven2/org/codehaus/groovy/groovy-all/2.0.6/groovy-all-2.0.6.pom
Download http://repo1.maven.org/maven2/net/saliman/gradle-cobertura-plugin/2.2.2/gradle-cobertura-plugin-2.2.2.jar
Download http://repo1.maven.org/maven2/org/codehaus/groovy/groovy-all/2.0.6/groovy-all-2.0.6.jar
FAILURE: Build failed with an exception.
* Where:
Build file '/tmp/build_2be-36-41-8-91a50/build.gradle' line: 10
* What went wrong:
A problem occurred evaluating root project 'build_346f'.
Cause: No signature of method: org.gradle.api.internal.plugins.DefaultConvention.create() is applicable for argument types: (java.lang.String, java.lang.Class, org.gradle.api.internal.project.DefaultProject_Decorated) values: [cobertura, class net.saliman.gradle.plugin.cobertura.CoberturaExtension, root project 'build_4dyre0']
Possible solutions: iterator()
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 7.539 secs
! Failed to build app
! Push rejected, failed to compile Gradle app
here is the part of my build that introduces the plugin - and the error:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "net.saliman:gradle-cobertura-plugin:2.2.2"
}
}
apply plugin: 'cobertura'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
apply plugin: 'checkstyle'

as it turns out, heroku have a pretty old standard Gradle buildpack. I had to change it with one that makes use of a newer version of my favourite build tool, Gradle.
BUILDPACK_URL: https://github.com/krro/heroku-buildpack-gradle.git
I did so by setting the heroku config propery above.
more about this topic: http://www.wiredforcode.com/blog/2014/02/11/deploy-to-heroku-with-gradle

Related

Gradle: Invalid publication 'maven': artifact file does not exist

Java 11 and Gradle 7.2 here. I am trying to build a reusable library that I can (eventually) publish to a Maven repository and pull into other projects. But first I just want to get it publishing to my local m2 repo.
The project directory structure looks like:
mylib/
lib/
src/
build.gradle
Where build.gradle is:
plugins {
id 'java-library'
id 'maven-publish'
id 'io.freefair.lombok' version "6.5.0-rc1"
}
sourceCompatibility = 1.11
targetCompatibility = 1.11
archivesBaseName = 'mylib'
version = '1.0.0-RC1'
group = 'org.example'
repositories {
mavenCentral()
}
dependencies {
// omitted for brevity
)
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
}
publishing {
publications {
maven(MavenPublication) {
artifact("build/libs/${archivesBaseName}-${version}.jar") {
extension 'jar'
}
}
}
}
tasks.named('test') {
useJUnitPlatform()
}
publishToMavenLocal.configure {
mustRunAfter build
}
When I run gradle publishToMavenLocal I get:
% ./gradlew clean build publishToMavenLocal
> Task :lib:publishMavenPublicationToMavenLocal FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':lib:publishMavenPublicationToMavenLocal'.
> Failed to publish publication 'maven' to repository 'mavenLocal'
> Invalid publication 'maven': artifact file does not exist: '/Users/myuser/workspace/mylib/lib/build/libs/mylib-1.0.0-RC1.jar'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 833ms
6 actionable tasks: 6 executed
So it looks like even though I'm specifying (on the command line) to run clean then build then publishToMavenLocal, and even though I'm even specifying (in build.gradle) that publishToMavenLocal must run after build, it seems what is happening is:
publishToMavenLocal insists on running first (before clean or build)
Since the JAR hasn't been built yet, no JAR file exists at the location specified ("build/libs/${archivesBaseName}-${version}.jar")
The build fails because the artifact doesn't exist
So I think I just need to get build to run before publishToMavenLocal but I'm out of ideas.
You're mixing the plugins DSL (plugins { }) with legacy plugin application (apply plugin). That's not a big deal, but you should go with #sean's answer and use the plugins DSL instead which will solve your issue.
To your problem at hand
Could not get unknown property 'plugin'
That happens because you missed the : in apply plugin
apply plugin: 'maven-publish'
Try placing your plugins in this way. Not sure if that resolves your issue though.
plugins {
id 'java-library'
id 'maven-publish'
}

Gradle does not see a plugin that is on the plugin portal

Gradle 4.6 here. Trying to use markdown-gradle-plugin to convert markdown files into HTML as part of my build. My build.gradle specifies:
plugins {
id 'com.github.johnrengelman.shadow' version '4.0.4'
id 'java'
id 'edu.sc.seis.launch4j' version '2.4.6'
id 'org.kordamp.gradle.markdown' version '2.0.0'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
compile(
'ch.qos.logback:logback-classic:1.2.3'
... (all of my dependencies here)
)
}
... rest of my build.gradle here
When I run:
./gradlew clean markdownToHtml
I get:
$ ./gradlew clean markdownToHtml
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/myuser/workspace/myapp/build.gradle' line: 14
* What went wrong:
An exception occurred applying plugin request [id: 'org.kordamp.gradle.markdown', version: '2.0.0']
> Failed to apply plugin [id 'org.kordamp.gradle.markdown']
> Could not find method register() for arguments [markdownToHtml, class org.kordamp.gradle.plugin.markdown.tasks.MarkdownToHtmlTask, org.kordamp.gradle.plugin.markdown.MarkdownPlugin$1#3b46a8ba] on task set of type org.gradle.api.internal.tasks.DefaultTaskContainer.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
I can verify that I do see the 2.0.0 version of the plugin on the Gradle plugin portal.
Can anybody spot where I'm going awry?
According to the kordmap plugins website:
Java 8 and Gradle 5 are the minimum requirements to use any of these
plugins.
So your version of gradle needs an upgrade.
The error is coming from when the plugin attempts to use TaskContainer::register, which was introduced in gradle 4.9, so you might be safe to upgrade to version 4.9, but I'd suggest going with what the website says and bumping it to version 5.

Plugin with id 'org.ajoberstar.grgit' not found

I'm trying to compile an opensource minecraft mod called VeinMiner.
I use ./gradlew build to compile it.
However it failed and give me this reason:
FAILURE: Build failed with an exception.
* Where:
Build file '/home/xxxx/Desktop/VeinMiner/build.gradle' line: 26
* What went wrong:
A problem occurred evaluating root project 'VeinMiner'.
> Plugin with id 'org.ajoberstar.grgit' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 14.778 secs
I have tried to git clone it again or run it in sudo.
However, neither of these two work.
This build gradle is like this:
(It's too long so I select some part of it)
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}
}
plugins {
id 'com.matthewprenger.cursegradle' version '1.0.7'
id 'org.ajoberstar.grgit' version '1.3.2'
}
apply plugin: 'forge'
apply plugin: 'maven'
apply plugin: "org.ajoberstar.grgit"
apply plugin: "com.matthewprenger.cursegradle"
ext.git = grgit.open(file('.'))
ext {
configFile = file "build.properties"
revision = git.head().abbreviatedId
depth = git.log().size()
}
I expected to Build Successful. Have anyone met this situation?
The mentioned plugin org.ajoberstar.grgit gets applied twice. The first time it gets applied via the new plugins block, the second time via the old apply plugin: method. Simply remove the line apply plugin: "org.ajoberstar.grgit" and the error should disappear.
To apply plugins via the old apply plugin: method, the plugin package needs to be resolved from an arbitrary repository inside the buildscript block. This works in the same way as resolving project dependencies via the normal repositories and dependencies blocks.
The new plugins block directly resolves plugins from the Gradle plugin portal and applies them in the same step.
I would guess that the way how to apply to plugin was changed to the newer one, but the removal of the old method did not happen. In existing setups the plugin may have been resolved from the local Gradle cache, but on your new setup it could not be found.

Task ‘bintrayUpload’ not found in root project after update Android studio to 3.0

Before I update gradle and android studio I used to upload my library to bintray with these tasks from this tutorial:
first: gradlew install
second: gradlew bintrayUpload
But after updating android studio and gradle I had to change fist task to: gradlew installDebug
but gradle can not find taskbintrayUpload and I get this error:
* What went wrong:
Task 'bintrayUpload' not found in root project 'MyProject'.
* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
You need to define a bintray task in your build.gradle. Since you do not have one, gradlew cannot find and therefore execute that task. Define something like the following according to your settings and you will be fine.
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'
bintray {
user = ...
key = ....
publications = ....
pkg {
...
}
}
The solution was here: I had to add these lines in lib gradle.
// Place it at the end of the file
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
And it loads and adds bintray tasks to the gradle.

Debug Gradle plugins with IntelliJ

Problem
I want to use the interactive debugger with IntelliJ. Unfortunately, I can't convince IntelliJ to load and compile the plugin. However, I can do gradle clean build and the plugin builds and runs its tests as expected.
Specifically, I'm trying to debug local changes to gradle-js-plugin and IntelliJ says it can't find com.google.javascript.jscomp.CompilerOptions as well as spock.lang.Specification. (I'm thinking maybe it's something about the way they are loaded, but that's a guess.)
Things I've tried
NOTE: I didn't revert any processes between steps.
0. My First Guess
I noticed a howto on docs.codehaus.org. IntelliJ couldn't find org.gradle.launcher.GradleMain, so I've adapted it to use GradleLauncher with the following:
import org.gradle.GradleLauncher
class GradleScriptRunner {
public static void main(String[] args) {
GradleLauncher.newInstance(
"-p",
"/path/to/gradle-js-plugin/src/test/resources/build.gradle",
"clean assemble"
)
}
}
Per GradleLauncher's documentation.
Outcome: IntelliJ won't compile the project.
1. Per Peter Niederwieser's answer Fix idea project & debug via plugin
Steps
~# cd /path/to/gradle-js-plugin && gradle cleanIdea idea
Opened the newly created project and attempted to debug using the ScriptRunner from step 0.
Outcome: Project compiles (yay!), but I can only hit breakpoints in GradleScriptRunner.groovy.
2. Per Peter Niederwieser's answer run gradle CLI w/ special options
1 & 2. Merged for clarity:
~# export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
~# gradle clean assemble
Listening for transport dt_socket at address: 5005
Configure IntelliJ to connect to this port and start debugging (see image):
For this step I tried the following .gradle file configurations:
1. Use only build.gradle
--build.gradle--
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'js'
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile findProject "/path/to/gradle-js-plugin"
}
}
repositories {
mavenLocal()
mavenCentral()
}
Outcome:
FAILURE: Build failed with an exception.
* Where:
Build file '/path/to/gradle-js-plugin/src/test/resources/build.gradle' line: 13
* What went wrong:
A problem occurred evaluating root project 'resources'.
> No such property: findProject for class: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 8 mins 50.498 secs
2. Use both build.gradle and settings.gradle
--settings.gradle--
include "/path/to/gradle-js-plugin"
--build.gradle--
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'js'
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
}
repositories {
mavenLocal()
mavenCentral()
}
Outcome:
FAILURE: Build failed with an exception.
* Where:
Build file '/path/to/gradle-js-plugin/src/test/resources/build.gradle' line: 5
* What went wrong:
A problem occurred evaluating root project 'resources'.
> Plugin with id 'js' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 13.553 secs
My Setup
Gradle
~# gradle -v
------------------------------------------------------------
Gradle 1.0
------------------------------------------------------------
Gradle build time: Tuesday, June 12, 2012 12:56:21 AM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Ivy: 2.2.0
JVM: 1.7.0_04 (Oracle Corporation 23.0-b21)
OS: Linux 3.2.0-2-amd64 amd64
Java
~# java -version
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
IntelliJ
IntelliJ IDEA Ultimate 117.499 w/ Bundled Gradle plugin
Hoping for
Any tips that'll get me into debug mode within the plugin.
I was able to debug gradle sources (including plugins) using -Dorg.gradle.debug=true (found on gradle forum):
Stop daemons if any:
./gradlew --stop
Run
./gradlew <task> --no-daemon -Dorg.gradle.debug=true
Connect remotely to gradle process (port 5005) - if using IntelliJ IDEA, see OP's image above
It should stop on breakpoints now.
BTW, I have created a separate IntelliJ IDEA project for gradle sources. Since I use gradle wrapper, I have grabbed the sources from
~/.gradle/wrapper/dists/gradle-1.11-all/7qd8qq8te5j4f5q9aaei3gh3lj/gradle-1.11/src
In IDEA I did File->Import Project, then selected the above path, then - "Create project from existing sources". Hit Next couple of times (made sure I didn't include any jars from lib/plugins directory, since IDEA would complain that most project files already exist).
I then created a remote debug configuration in that IDEA project and used it for debugging gradle.
First, it sounds like there is a problem with your IDEA Gradle project. If you run gradlew cleanIdea idea and then open the generated project from IDEA (rather than using the JetGradle plugin), all should be fine.
Second, if you still can't get the GradleMain/GradleLauncher (the former class does exist) approach to work, another approach is to debug the Gradle build as an external application. For that you need to add -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 to the GRADLE_OPTS environment variable, run the build from the command line, wait until it suspends, and then start a "Remote" run configuration (with corresponding settings) from IDEA. At that point the debugger should connect to the Gradle process and you should be up and running.
IntelliJ IDEA 12.1 provides ability to debug gradle tasks out of the box - right-click target task at the JetGradle tool window tasks list and choose 'debug'

Resources