Menu
  • HOME
  • TAGS

Groovy generated constructor missing during compile

Tag: groovy,gradle

I have a setup in which I call the generated constructor(@TupleConstructor) of a Groovy class(Product) from a java class(ProductService). The IDE shows the generated constructors and compilation used to work. But now, for unknown reasons, the compilation fails because the compiler doesnt find the parameterized constructors anymore:

ProductService.java:31: error: constructor Product in class Product cannot 
be applied to given types; 
required: no arguments  
found: String,boolean,boolean,float 
reason: actual and formal argument lists differ in length

And this is my current gradle(2.4) setup:

apply plugin: 'groovy'
apply plugin: 'java'

project.sourceCompatibility = 1.8
project.targetCompatibility = 1.8

sourceSets.main.java.srcDirs = []
sourceSets.main.groovy.srcDir 'src/main/java'
...
dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.+'
    testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
}

Groovy class:

@TupleConstructor
class Product {
    String name
    boolean bool1
    boolean bool2
    float price
}

Constructor call in Java class(fails to compile):

...
products.add(new Product("Parliament", true, false, 10.50F));
...

Best How To :

Analysis:

This looks to me like a joint compilation issue. Most likely the transform @TupleConstructor runs after Groovy did create the .java stub files, causing the java compilation part to fail. It could have worked before, because you compiled the groovy part independent and then reused existing class files (no clean). Sadly this is a limitation of the stub generator and there is not really a way to fix the issue in Groovy, if the transform is supposed to stay in the same phase.

Solutions:

  • use the groovy-eclipse batch compiler
  • don't use transforms that run after the stub generator
  • create a multi module build in gradle, that will compile the groovy part independent

Grails JAX-RS Calling a class in src/groovy giving error - Message: No signature of method: is applicable for argument types

grails,groovy,jax-rs

either use new ValidateToken.validate(... or make your validate method static. this is actually what the error is stating: No signature of method: static ....ValidateToken.validate() is applicable for argument types: () values: []` ...

Gradle: Adding sources.jar file within /lib folder of published dist.zip along with all my other dependencies

java,maven,jar,gradle

You need to tell the application plugin to include the output of your sourcesJar task in the distribution: distributions { main { contents { from sourcesJar } } } That will place it in the root, if you want it somewhere else you can do this: distributions { main {...

create email list of all users

groovy,jenkins,jenkins-scriptler

First of all you should know that Jenkins will not always be able to tell you whether the user exists or not. From Jenkins' javadoc: This happens, for example, when the security realm is on top of the servlet implementation, there's no way of even knowing if an user of...

Android studio gradle flavor dimensions build varients not working correctly

android-studio,gradle,android-gradle,build.gradle,android-productflavors

I think you misunderstood the concept of flavorDimension. A flavorDimension is something like a flavor category and every combination of a flavor from each dimension will produce a variant. In your case, you must define one flavorDimension named "type" and another dimension named "organization". It will produce, for each flavor...

How does the Groovy compiler work?

groovy

Groovy parses the source code with antlr via the groovy grammar description, then generates bytecode using asm It does not require javac...

sonar maven analysis only picks .java file

maven,groovy,sonarqube,sonarqube-5.0

Since it was a multi module project, I had to include the properties sonar.sources and sonar.tests in all the module's pom.xml file. <properties> <sonar.sources>src/main</sonar.sources> <sonar.tests>src/test</sonar.tests> </properties> ...

Decode base64 image in Grails [duplicate]

grails,groovy

Base64 uses Ascii characters to send binary files, so to retrieve your image, you basically have to decode the Base64 string back to a byte array and save it to a file. String encoded = 'iVBORw0KGgoAAAANSUhEUg' // You complete String encoded.replaceAll("\r", "") encoded.replaceAll("\n", "") byte[] decoded = encoded.decodeBase64() new File("file/path").withOutputStream...

Special Groovy magic re property access and collections / iterables?

groovy

That's the GPath expression documented (ish) here, and yes, it only works for properties. (There's an old blog post by Ted Naleid here about digging in to how it worked in 2008) For methods, you need to use *. or .collect() See also: Groovy spread-dot operator Better docs link (as...

Cron expression must consist of 6 fields (found 1 in “#{systemEnvironment['db_cron']}”)

spring,groovy,cron,spring-el

You should set env variable like you do: export db_cron="0 19 21 * * *" then restart your ide if you are using or restart your terminal session. @Scheduled(cron = "${db_cron}") def void schedule() { ... } I tried it and here is my screenshot. Everything works as expected......

Issue building project on Android Studio - support-v4

android,gradle,android-gradle,build.gradle

Alrighty the solution was to update gradle on build.gradle of my project, not module // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.2.3' } } allprojects { repositories { jcenter() } } it was set...

How to download a library dependence on gradle for external use?

cordova,android-studio,gradle,android-gradle,cordova-plugins

What you're looking for is an aar file. You can copy this file to lib folder with the following script: apply plugin: 'java' repositories { mavenCentral() } dependencies { compile 'io.filepicker:filepicker-android:[email protected]' } task copyLibs(type: Copy) { from configurations.compile into 'lib' } ...

groovy/XML: Replace a node by another one

xml,groovy,xml-parsing,xmlslurper

Here you go: import groovy.xml.* def xml = '''<myXml> <myNode> <Name>name1</Name> <Name>name2</Name> <Name>name3</Name> </myNode> </myXml>''' def namelist = ['name4','name5','name6','name7'] def slurped = new XmlSlurper().parseText(xml) slurped.myNode.replaceNode { myNode { namelist.collect { n -> Name "$n" } } } new StreamingMarkupBuilder().bind { mkp.yield slurped }.toString() The node was in fact replaced but...

Using ant.replace in gradle

replace,ant,gradle

It should be: task writeVersion << { ant.replace( file: 'version.txt', token: 'versionNumber', value: '1.0.0' ) } and: version.number=versionNumber ...

Gradle Exec : Why it is not running in configuration phase?

gradle,exec,mkdir

Please have a look at AbstractExecTask from which Exec inherits. As you can see there are lots of getters and setters. What happens at configuration time is setting the values for that fields only, not running them. All the properties set will be used in only when exec() method annotated...

Adding Android AppWidget just for one Product Flavor

android,gradle,android-appwidget,android-productflavors

So we will have our example packages is as follows for your production and staging builds within the gradle product flavors. productFlavors { production { packageName "x(path).x(path).gradleexample" } staging { packageName "x(path).x(path).gradleexample.staging" } } Here is an example of your folder structure some of which may or may not apply...

Install gradle on Centos

jenkins,gradle

... but when I unzipped I got gradle.bat file inside bin directory which tells me that this is for Windows. It also contains a file called gradle, which is a shell script. Your download is also suitable for running on any Linux or UNIX platform .... including CentOS....

How to use Library from GitHub in android App

android,github,gradle,libraries

You have add path to your aFileDialog library in your settings.gradle Make sure that folder you point to includes build.gradle file include ':app' include ':aFileDialog' project(':aFileDialog').projectDir = new File(settingsDir, 'aFileDialog') or (judging from the library folder structure on GitHub) project(':aFileDialog').projectDir = new File(settingsDir, 'aFileDialog/library') ...

Automatically copy .so files from NDK library project?

android-studio,gradle,android-ndk

I does not know if ther is a way to have you .so files copied as you want whiout wirtting anything. But you could have gradle doing it for you. In your gradle file, add a task that copy those .so files where you need them to be. android {...

what is gradle missing to map hibernate?

java,hibernate,gradle

I think the problem is not really with gradle. It's with the fact that the JPA spec stupidly requires that the classes of the entities are in the same jar/directory as the persistence.xml file. And since Gradle doesn't store the "compiled" resources in the same output directory as the compiled...

Groovy - timestamp from minutes

oracle,grails,groovy,timestamp

I assume you want to use the current day offset with the number of minutes given for your timestamp. Since a new Date or Timestamp will be initialized to the current time and date, you can use that and override the minute field with the values from your array. Values...

using classes in jenkins job dsl

groovy,jenkins,jenkins-job-dsl

When using println in scripts (in your example, in the runIt function), Groovy sends the call to a out variable defined in the script's binding or to System.out.println if the variable is not set. The Job DSL plugin sets this variable so that the output goes to the build log....

Groovy: run SQL SELECT LIKE from file with params

sql,select,groovy

try this SELECT * FROM [db].[dbo].[TABLE] WHERE [ID] LIKE '%'+convert(varchar(50),:id)+'%' ...

Android Studio and gradle

android,android-studio,gradle

So I have found the solution at this http://www.alonsoruibal.com/my-gradle-tips-and-tricks/. The trick is in your Java Library module's build.gradle file you need to include the following. apply plugin: 'java' sourceCompatibility = 1.6 targetCompatibility = 1.6 Wrong Java Compiler When Including a Java Module as Dependency in Android Studio...

Class fields as method parameters

oop,groovy

Assuming your EntityQuery.groovy ( model )looks like : private String typeName private Order order Assuming you have Order.groovy ( model ) that looks like : private String fieldName; private String orderType; private String orderName; use these model chain as a parameter, I think that is still strongly-typed (correct me). Your...

Model to LazyMap

dictionary,groovy,deserialization

You can use jackson-databind. E.g. @Grab('com.fasterxml.jackson.core:jackson-databind:2.5.4') import com.fasterxml.jackson.databind.ObjectMapper class AccessCredentials { String userName = 'Between The Buried And Me' String password = 'Alaska' LoginOptions loginOptions = new LoginOptions() } class LoginOptions { String partnerId = 'Colors' String applicationId = 'The Great Misdirect' } def mapper = new ObjectMapper() assert mapper.convertValue(new...

Deploy closed source aar maven repo to github

android,git,maven,github,gradle

use the raw link, try changing blob for raw: http://downright-amazed.blogspot.com/2011/09/hosting-maven-repository-on-github-for.html...

Android Studio work with module

java,android,android-studio,gradle

You need to check all Manifest files and ensure your modules are not providing activity with <intent-filter> used by Lauchers: <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> Also ensure your module's build.gradle for module is lists apply plugin: 'com.android.library' (as it should), and not apply plugin: 'com.android.application' (which is not correct)...

Spock's @Narrative and @Title annotations

groovy,spock

Title is expected to be a single line (short description) Narrative should be full paragraphs (using a Groovy multi-line string) They are mostly used in big projects where Narrative text could be read by business analysts, project managers e.t.c. As Opal said these will be more useful once some reporting...

Is it possible to exclude specific build variant when using flavor Dimensions?

android,gradle

Since Gradle 0.9 you can apply a variant filter and iterate over them: productFlavors { freeapp { dimension "version" } x86 { dimension "abi" } paidapp { dimension "mips" } } // Loop variants android.variantFilter { variant -> // Loop flavors variant.getFlavors().each { flavor -> println variant.buildType.name + " "...

Write Spock test cases for Spring boot application

java,spring,groovy,spock

Yes, you can write spock test cases for your spring application. Look at the official documentation for an example of Spock testing with Spring Boot 35.3.1 Using Spock to test Spring Boot applications A simple google search reveals a basic example of Using Spock to test Spring classes. Spock relies...

Gradle Assemble Debug is Successful But Does Not Work [duplicate]

android,command-line,gradle

Look for build outputs under the app module. app/build/outputs/...

Gradle multi-project custom build.gradle file name

gradle,build,multi-project

A simple web search for "gradle rename build.gradle" renders the below example settings.gradle file: rootProject.buildFileName = 'epub-organizer.gradle' rootProject.children.each { project -> String fileBaseName = project.name.replaceAll("\p{Upper}") { "-${it.toLowerCase()}" } project.buildFileName = "${fileBaseName}.gradle" } Note that the author is here also renaming the root project's build script, which you may or may...

How to create different build variants pointing to different Servers?

android,gradle

It is really easy to do with gradle. productFlavors { first_server { buildConfigField "String", "SERVER_URL", "\"https://first_server_url/\"" } second_server { buildConfigField "String", "SERVER_URL", "\"https://second_server_url/\"" } } You may want to find more information here. So later you can easy access this variable by BuildConfig.SERVER_URL...

Duplicate entry for class in gradle

java,android,android-studio,gradle

The above library is already on maven. Just remove the imported folder and add the code below to your dependencies: compile 'com.flaviofaria:kenburnsview:1.0.6' Sometimes due to downloading issues; the library fails to download. In that case ; just find your .gradle folder and clear cache inside it. Recompile and you are...

Restrict allowed httpMethods using enum

rest,groovy,enums

Is that what you're looking for: public enum HttpMethod { POST, DELETE, GET, PUT, HEAD, TRACE, CONNECT, PATCH } class EntityQuery { String field1 String field2 } def createEntity(HttpMethod h, EntityQuery q) { if(!(h in [HttpMethod.POST, HttpMethod.GET])) { throw new Exception('Only POST and GET methods allowed') } } createEntity(HttpMethod.PUT, new...

Add project on outer level as dependency to module

android,intellij-idea,gradle

Add dependencies in the 'build.gradle' of your MainProject, like this: compile project(':proj1') compile project(':proj2') EDIT: And in the 'settings.gradle' this: include ':proj1' project(':proj1').projectDir = new File('../proj1') include ':proj2' project(':proj2').projectDir = new File('../proj2') ...

Confused about the invokeMethod method in the Groovy MOP

groovy,mop

In short you are not using the standard meta class, so you don't get the standard Groovy MOP. Car.metaClass.invokeMethod = { will let Car have an ExpandoMetaClass as meta class. This meta class uses the invokeMethod you give in as open block (like you do) to intercept calls. This is...

Gradle Jar structure is different than the real project structure

java,jar,gradle,build

When your project is managed by gradle you should always use standard layout introduced by maven or have a good excuse to using any different layout. Here you can find sample project that shows how to use the this layout and read the resources that will be later included in...

Gradle & Jacoco: Get jacoco reports for Test-type task other than “test”

java,gradle,jacoco

Turns out, this works: task integTestReport (type: JacocoReport) { executionData project.tasks.integTest sourceDirectories = project.files(project.sourceSets.test.allSource.srcDirs) classDirectories = project.sourceSets.test.output def reportDir = project.reporting.file("jacoco/integTest/html") reports { html.destination = reportDir } doLast { println "See report at: file://${reportDir.toURI().path}index.html" } } I hope this is helpful :) EDIT: This needs to be later in the...

How to get testStep responseAsXml in groovyScript

groovy,soapui

If you want to get the response from com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep, a possible way is first get the testStep from this class using getTestStep() method. This method returns a object of class com.eviware.soapui.model.testsuite.TestStep, from this object you can get the testSteps properties like request, response, endpoint... using getPropertyValue(java.lang.string) method. So in your...

Get just content of soap response in Groovy

xml,soap,groovy

SO you could do this: import groovy.xml.* def xml = '''<?xml version="1.0" encoding="utf-8"?> |<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | <soap:Body> | <GetHTMLResponse xmlns="http://www.webserviceX.NET"> | <GetHTMLResult> | TEST | </GetHTMLResult> | </GetHTMLResponse> | </soap:Body> |</soap:Envelope>'''.stripMargin() def result = XmlUtil.serialize(new...

Paid and Free versions of android app

android,gradle,android-version

You could have two versions of the application in Play store. However, you would have to maintain these separately and it is frustrating to upgrade from free to paid with this approach. If you chose this way of maintaining your application, you would have to have two projects, one for...

gradle execute task after build

gradle,build.gradle

What you need is finalizedBy, see the following script: apply plugin: 'java' task finalize << { println('finally!') } build.finalizedBy(finalize) Here are the docs....

scala minecraft forgemod 'gradle runClient' gives runtime exception

scala,gradle,akka,minecraft,minecraft-forge

I figured it out. application.conf had: provider = "akka.cluster.ClusterActorRefProvider" cluster isn't part of akka-actor its part of akka-cluster. I've switched to provider = "akka.actor.LocalActorRefProvider" That works now. The other option is to add akka-cluster to the dependancies list. If your actually trying to use ClusterActorRefProvider...

Exclude Package From Gradle Dependency

java,web-services,rest,gradle

I found out that com.sun.jersey:jersey-core:1.19 doesn't bundle the javax.ws.rs class files and instead lists them as a compile-time dependency. Adding this snippet to my build.gradle fixed the issue. configurations.all { resolutionStrategy { // For a version that doesn't package javax.ws force 'com.sun.jersey:jersey-core:1.19' } } ...

Visualizing gradle dependencies in Intellij

intellij-idea,gradle,intellij-14

I did a small search in IDEA and Google and looks like there is not way to see Gradle dependency but I have found the plugin "Gradle View" which does what you need http://plugins.jetbrains.com/plugin/7150 You can open a ticket and maybe they will add a better Gradle support in IDEA...

duplicate an android studio project

android,gradle,duplicates,project,sync

i think that i found the source of my problem it was a virtual machine problem. so the solution is : open file -> settings clic to : compiler in the VM option field put te following value: -Xmx512m That's all...

Spock Framework: problems with spying

java,unit-testing,groovy,spock,spock-spy

It should be: @Grab('org.spockframework:spock-core:0.7-groovy-2.0') @Grab('cglib:cglib-nodep:3.1') import spock.lang.* class CallingClassTest extends Specification { def "check that functionTwo calls functionOne"() { def c = Spy(CallingClass) when: def s = c.functionTwo() then: 1 * c.functionOne() >> "mocked function return" s == "some string mocked function return" } } public class CallingClass { public...

Phonegap: Command failed with exit code 8

android,cordova,gradle

I have already managed to solve this problem, so, in case of anyone has a similar trouble, here it goes the situation I've gone through. When I performed the first build, phonegap attempted to download and extract it's own gradle distribution, and he was attempting to download it from the...

Android build project error trying to build apps > 65K (65536) methods

android,android-studio,gradle,build,android-gradle

You need to reduce the size or include only the imports you need to for your application. You are hitting the dex limit of 65536 methods. Here's the link Building Apps with Over 65K Methods which might help....