superxp1412
superxp1412

Reputation: 21

How to import external gradle script file with plugins imported correctly in Gradle?

I encountered a plugin importing error when applying from an external Gradle script file. For example: In file gradle/lambda.gradle:

apply plugin: 'base'
apply plugin: 'jp.classmethod.aws.lambda'

import com.amazonaws.services.lambda.model.InvocationType;

import jp.classmethod.aws.gradle.lambda.AWSLambdaDeleteFunctionTask;
import jp.classmethod.aws.gradle.lambda.AWSLambdaInvokeTask;
import jp.classmethod.aws.gradle.lambda.AWSLambdaMigrateFunctionTask;
import jp.classmethod.aws.gradle.lambda.AWSLambdaPublishVersionTask;
import jp.classmethod.aws.gradle.lambda.AWSLambdaCreateAliasTask;
import jp.classmethod.aws.gradle.lambda.AWSLambdaUpdateAliasTask;

import jp.classmethod.aws.gradle.lambda.VpcConfigWrapper

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

    }
    dependencies {
        classpath "jp.classmethod.aws:gradle-aws-plugin:0.38"
    }
}

In build.gradle file I apply the external script by this method:

apply from: 'gradle/lambda.gradle'

But it will produce an error about the plugin imports:

Plugin with id 'jp.classmethod.aws.lambda' not found.

It can be resolved by including the same buildscript code block in build.gradle file.

What's the root cause of this issue? What's the recommended way to achieve this goal?

Upvotes: 2

Views: 2714

Answers (1)

ToYonos
ToYonos

Reputation: 16833

Based on my answer here, you should do this :

What you can do on the other hand is to put your buildscript block into the build.gradle file of the root project and then all other build files from subprojects will inherit this block.

edit : it won't work due to the import. classpath "jp.classmethod.aws:gradle-aws-plugin:0.38" is needed in gradle/lambda.gradle for the resolving the import, it's also needed in build.gradle as the plugin jp.classmethod.aws.lambda is apply from here (through the apply from)

Upvotes: 0

Related Questions