greenrobot / greenDAO

greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.
http://greenrobot.org/greendao/
12.63k stars 2.89k forks source link

SourceSet with name 'main' not found. #1049

Closed rayastar closed 1 year ago

rayastar commented 3 years ago

Hello. I have greendao generator in my project and it worked retty good. But today it doesn't work. It's very abnormal, because it's earlier worked . I download example from rep, and it's doesn't work too. The same error. Can you help me?

* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:GreenDaoGenerator.main()'.
   > SourceSet with name 'main' not found.

my source set:

sourceSets {
    main {
        java {
            srcDir 'src'
        }
        resources {
            srcDir 'src-template'
        }
    }
    test {
        java {
            srcDir 'src-test'
        }
    }
}
silvagoncalodev commented 1 year ago

It's been 2 years, but I'm leaving my solution here in case someone else has the same issue.

In recent versions of Android Studio, the IDE will refuse have to run Java main() methods if the module is not declared as a pure Java library.

In your build.gradle file of the generator module, if you have apply plugin: 'com.android.library', change it to: plugins { id 'java-library' }

And remove all Android blocks from the file. After applying these changes it should look like this:

plugins {
    id 'java-library'
}

dependencies {
    implementation "org.greenrobot:greendao-generator:$greendao_version"
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7
}

You should be able to run the generator without any issues.

greenrobot-team commented 1 year ago

@silvagoncalodev Thanks for sharing! Closing this as it's really outdated.