Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load class 'org.gradle.kotlin.dsl.precompile.v1.PrecompiledProjectScript'. #108

Closed
mariuspena opened this issue Feb 10, 2020 · 17 comments · Fixed by #112
Closed
Labels
question Further information is requested

Comments

@mariuspena
Copy link

mariuspena commented Feb 10, 2020

Hi.
made a new project, gradle version 3.5.3 (<<< EDIT: actually it is 5.4.1)
added in the the module gradle file:

buildscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath "com.yelp.codegen:plugin:1.3.0"
    }
}
apply plugin: "com.yelp.codegen.plugin"
generateSwagger {
    platform = "kotlin"
    packageName = "com.yelp.codegen.samples"
    inputFile = file("./sample_specs.json")
    outputDir = file("./src/main/java/")
}

but I get this error:
Unable to load class 'org.gradle.kotlin.dsl.precompile.v1.PrecompiledProjectScript'.

can somebdoy help me ? thx!

@cortinico
Copy link
Collaborator

Hi @mariuspena, thanks for using this project.

made a new project, gradle version 3.5.3

As described in the README at the "Requirements" section, you need to have Gradle 5+ to use this plugin:
https://github.com/Yelp/swagger-gradle-codegen/blob/master/README.md#L55-L60

We can't support you further till you update Gradle.

@cortinico cortinico added the question Further information is requested label Feb 10, 2020
@mariuspena
Copy link
Author

my bad. my gradle version is: 5.4.1

@cortinico cortinico reopened this Feb 10, 2020
@cortinico
Copy link
Collaborator

Thanks for the update

added in the the module gradle file:

Can you please provide more context? Are you able to link your project?
Could you please post both the root project gradle file and the module gradle file?

My gut feeling is that this failure is unrelated to the plugin, but I don't have enough context to tell you at this point.

@mariuspena
Copy link
Author

mariuspena commented Feb 10, 2020

top level gradle file:


buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and the module gradle file:

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

def keystorePropertiesFile = rootProject.file("../certificates/keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    signingConfigs {
        upload {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

    defaultConfig {
        applicationId "com.test.android"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        setProperty("archivesBaseName", "test" + "-" + versionCode + "(" + versionName + ")")

        buildConfigField "String", "BCF_API_ENDPOINT", "\"https://d63250ed.ngrok.io\""
    }

    buildTypes {
        release {
            debuggable false
            minifyEnabled true
            shrinkResources true
            zipAlignEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.upload
        }
        debug {
            debuggable true
            minifyEnabled false
            shrinkResources false
            zipAlignEnabled false
        }
    }

    flavorDimensions "audience"
    productFlavors {
        consumer {
            dimension "audience"
            applicationId "com.test.consumer"
            resValue "string", "app_name", "@string/app_name_consumer"
        }
        producer {
            dimension "audience"
            applicationId "com.test.producer"
            resValue "string", "app_name", "@string/app_name_producer"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

// For this module only
repositories {
    maven { url "https://plugins.gradle.org/m2/" }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    def lifecycle_version = "2.2.0"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    //    implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"    // For Java
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"

    // rxJava2
    implementation "io.reactivex.rxjava2:rxjava:2.2.2"
    implementation "io.reactivex.rxjava2:rxandroid:2.0.2"
    implementation "com.jakewharton.rxrelay2:rxrelay:2.1.0"

    // Dagger2
    def dagger_version = "2.26"
    implementation "com.google.dagger:dagger:$dagger_version"
    implementation "com.google.dagger:dagger-android-support:$dagger_version"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    kapt "com.google.dagger:dagger-compiler:$dagger_version"
    kapt "com.google.dagger:dagger-android-processor:$dagger_version"
    //    annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"         // For Java user annotationProcessor
    //    annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version"// For Java user annotationProcessor

    // Retrofit
    def retrofit_version = "2.7.1"
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"

    implementation "com.squareup.okhttp3:logging-interceptor:4.3.0"
    implementation "com.facebook.stetho:stetho-okhttp3:1.5.1"


    // testing
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'

}

buildscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
    }

    dependencies {
        classpath "com.yelp.codegen:plugin:1.3.0"
    }
}

apply plugin: "com.yelp.codegen.plugin"

generateSwagger {
    platform = "kotlin"
    packageName = "com.yelp.codegen.samples"
    inputFile = file("./sample_specs.json")
    outputDir = file("./src/main/java/")
}```

@cortinico
Copy link
Collaborator

Hey @mariuspena

Looks like the problem is that you're not properly configuring the plugin.
Can I ask you to update your top level gradle file with this:

buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.yelp.codegen:plugin:1.3.0"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

[ REST OF THE FILE AS BEFORE ]

And please remove the buildscript block from the module gradle file?
Please let me know if this solved your issue.

@cjheyday
Copy link

cjheyday commented Feb 12, 2020

I am having the same issue and getting this error info:

Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)

The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)

Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

Also using gradle 5.4.1, build tools 3.5.3 and com.yelp.codegen:plugin:1.3.0. My top level gradle file looks like the one right above.

The issue disappears when downgrading to com.yelp.codegen:plugin:1.2.0

@macisamuele
Copy link
Collaborator

@mariuspena , @cjheyday: I'm not entirely sure about the issue but I'd like to ask if is possible to have a sort of minimal sample project that triggers the issue (maybe a git repo).
Doing it helps us making sure that we're observing and reproducing the same issue you're reporting and so we might be able to provide a more detailed answer.

@mariuspena
Copy link
Author

hey there. I updated the gradle files but I get the same error.
here is a new project you can test https://github.com/mariuspena/TestYelpCodegen

@macisamuele
Copy link
Collaborator

I'm not 100% sure yet on how gradle plugin are built and linked so I need to find more documentation and/or having @cortinico / @filipemp / @martinbonnin confirming this.

The main difference (at gradle level) between version 1.2.0 and 1.3.0 of the plugin is in the gradle version use to build it (it moved from 5.5 to 6.1).


I've tried to build the current master by using gradle version 5.5

swagger-gradle-codegen $ git diff
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 31a0802..ee69dd6 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
swagger-gradle-codegen $ ./gradlew --project-dir gradle-plugin :plugin:publishPluginMavenPublicationToPluginTestRepository
...

and to rebuild the test project using the local maven repository to fetch the plugin

TestYelpCodegen $ git diff
diff --git a/build.gradle b/build.gradle
index 3d4ae48..6864562 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,9 +3,12 @@
 buildscript {
     ext.kotlin_version = '1.3.61'
     repositories {
+        maven {
+            name = "pluginTest"
+            url = uri("file:///home/macisamuele/github/swagger-gradle-codegen/gradle-plugin/build/localMaven")
+        }
         google()
         jcenter()
-        maven { url "https://plugins.gradle.org/m2/" }
     }
     dependencies {
         classpath 'com.android.tools.build:gradle:3.5.3'

and it worked.
NOTE: It will continue to work if we use gradle 6.1 on TestYelpCodegen

Considering the above points I'm inclined to think that if we publish the plugin with a given version of gradle then it will be usable by the same major release of gradle or above.
So as for now version 1.3.0 is supported for gradle 6+ and as project maintainers we should be very careful on bumping the gradle version.

If the findings above are confirmed we should definitely update the readme to mention it

@martinbonnin
Copy link
Contributor

martinbonnin commented Feb 12, 2020

This seems to be related to the kotlin-dsl plugin. @mariuspena do you use it in buildSrc by any chance ? Then maybe it's loading an incompatible version ?
Something else worth trying is to make sure everything is compiled with the same kotlin version (1.3.61 in this case).

In all cases, we should certainly check the Gradle version when applying the plugin. I'll look into it .

@cjheyday
Copy link

This seems to be related to the kotlin-dsl plugin. @mariuspena do you use it in buildSrc by any chance ? Then maybe it's loading an incompatible version ?
Something else worth trying is to make sure everything is compiled with the same kotlin version (1.3.61 in this case).

In all cases, we should certainly check the Gradle version when applying the plugin. I'll look into it .

I am using buildSrc so that could be the issue.

@martinbonnin
Copy link
Contributor

I am using buildSrc so that could be the issue.

But the test project doesn't so it's not that. (Thanks @mariuspena for providing that, it helps a lot!).

It looks like the missing class has been added there: gradle/gradle@6279eda#diff-6b55abe0d82c89784c1a9bb1f8529a5d

That would be 6.1.0 if I understand correctly so @macisamuele you're right. The plugin jar contains code that's only consumable by 6.1.0. This sucks. Maybe we can remove the kotlin-dsl plugin and write the PluginClass ourselves ?

@cortinico
Copy link
Collaborator

cortinico commented Feb 13, 2020

Considering the above points I'm inclined to think that if we publish the plugin with a given version of gradle then it will be usable by the same major release of gradle or above.
So as for now version 1.3.0 is supported for gradle 6+ and as project maintainers we should be very careful on bumping the gradle version.

If the findings above are confirmed we should definitely update the readme to mention it

That's correct. It's actually because we can't control the version of gradleApi() that we're using here:

This is a Gradle limitation, more context here:
gradle/gradle#1835

The plugin jar contains code that's only consumable by 6.1.0. This sucks. Maybe we can remove the kotlin-dsl plugin and write the PluginClass ourselves ?

I don't think it's necessary to remove the kotlin-dsl plugin we're using. What we could do at this point in time is:

  1. Keep everything as it is and inform on the README that this plugin works only for Gradle 6.1+.
  2. Downgrade the version of Gradle we're using to the one we used before (5.6.2) and release an hotfix for the plugin (1.3.1) that is built using the former version of Gradle.

@mariuspena Can I ask you to upgrade Gradle to 6.1+ and confirm that everything works?

@macisamuele
Copy link
Collaborator

macisamuele commented Feb 13, 2020

@cortinico your proposal is already implemented in #111 .

About building TestYelpCodegen with gradle 6.1, I did already tried and it works

NOTE: It will continue to work if we use gradle 6.1 on TestYelpCodegen

release an hotfix

I think it is a bit complicate as on master we already have changes and new features

@cortinico
Copy link
Collaborator

@cortinico your proposal is already implemented in #111 .

Which of the two 😅

I think it is a bit complicate as on master we already have changes and new features

I don't think it's that complicate 🧐 I'll simply branch of top of the v1.3.0 tag and apply the fix over there.

@mariuspena
Copy link
Author

About building TestYelpCodegen with gradle 6.1, I did already tried and it works

so I changed the gradle wrapper here
distributionUrl=https://services.gradle.org/distributions/gradle-6.1-all.zip
to 6.1

It compiles. but I do not see any generated code

@macisamuele
Copy link
Collaborator

It compiles. but I do not see any generated code

To generate code you need to run /gradlew generateSwagger.
Be aware the test project does actually not build because swagger spec file isn't present.

> Task :app:generateSwagger FAILED

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':app:generateSwagger' (type 'GenerateTask').
> File '/home/maci/pg/TestYelpCodegen/app/sample_specs.json' specified for property 'inputFile' does not exist.

PR #111 fixed the issue and in the next days we'll provide a new plugin release that restores Gradle 5+ compatibility.

I'm closing this for know as the issue has been addressed and a temporary workaround has been identified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants