Rebar3 has its own macro to identify the current environment

I have an off-the-shelf tool that I want to integrate into the rebar3 plugin, and I want to do some special processing with the built-in macros

1 Like

Hi, @dong50252409.

In order to create a rebar3 plugin, you can start with rebar3 new plugin (rebar3 new help plugin to get help).

After that you need to fill in the code for the plugin to do what you want.

Plugins typically involve stuff like reading configuration from somewhere (e.g. rebar.config’s {ex_doc, []}), executing something over existing code (e.g. rebar3 ex_doc) and outputting execution results (e.g. folder docs/).

As far as I’m aware there’s no “generic” plugin where you just plug an executable and “it works” because the executable is usually accompanied by specific behaviour that the plugins needs to be coded for.

There’s many examples of rebar3 plugins you can use for inspiration: rebar3-plugin · GitHub Topics · GitHub.

1 Like

Thank you for your answer, but not the answer I was looking for, Maybe I wasn’t clear.

I want rebar3 to provide a macro to determine whether the program I am executing is initiated by rebar3, for example, I may need to call different functions in my code depending on whether the macro is defined or not.


info(F,A) ->
info(F,A) ->

What about using something that’s not a macro…

info(F, A) ->
    case erlang:function_exported(rebar_api, info, 2) of
        true -> rebar_api:info(F, A);
        false -> io:format(F, A)


info(F, A) ->
    try rebar_api:info(F, A)
        _:undef -> io:format(F, A)
1 Like

Thank you for your answer.
I know what to do, okay