Gradle plugin for custom language

本小妞迷上赌 提交于 2019-12-05 02:24:16

问题


I have a custom language (let's say it is MyLang but it can be any language) and I would like to make a plugin for it. The plugin needs to

  • be able to recognize the sourcesets for the language given with DSL
  • be able to compile them using an executable (the compiler)

I was able to create a plugin with a compile task (empty yet) and annotate a function with @LanguageType setting the language name to "mylang".

How can I modify the plugin to be possible to add sourcesets from build.gradle files using DSL like sourceSets { mylang { ... } }?

How can I modify the build task to be able to build the files of the source set?

  class MylangBuildPlugin implements Plugin<Project> {
    static final String COMPILE_TASK_NAME = 'compileMylang'

    void apply(Project project) {
        project.getPluginManager().apply(ComponentModelBasePlugin.class);
        createCompileTask(project)
    }

    @LanguageType
    void registerLanguage(LanguageTypeBuilder<BaseLanguageSourceSet> builder) {
        builder.setLanguageName("mylang");
        builder.defaultImplementation(BaseLanguageSourceSet.class);
    }


    private void createCompileTask(Project project) {
        project.task(COMPILE_TASK_NAME) {
        }
    }
  }

来源:https://stackoverflow.com/questions/33083444/gradle-plugin-for-custom-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!