I'm trying to add swagger to an existing demo project erlang_rest_api as a learning experience, but I don't seem to be getting very far...
I cloned the repos:
git clone https://github.com/dronowar/erlang_rest_api
Then I added cowboy_swagger to rebar.config:
{cowboy_swagger, ".*", {git, "git://github.com/inaka/cowboy_swagger.git"}}
And when I build I get:
Dependency not available: jsx-2.9.0 (undefined)
Dependency not available: cowboy-2.5.0 (undefined)
Dependency not available: ranch-1.6.2 (undefined)
Dependency not available: trails-2.1.0 (undefined)
So I add to rebar.config:
{jsx, ".*", {git, "git://github.com/talentdeficit/jsx.git", {tag, "2.9.0"}}},
{ranch, ".*", {git, "git://github.com/ninenines/ranch.git", {tag, "1.6.2"}}},
{trails, ".*", {git, "git://github.com/inaka/cowboy-trails.git", {tag, "2.1.0"}}},
And then I delete the deps directory and build again:
...
==> poolboy (get-deps)
==> sync (get-deps)
==> katana_test (get-deps)
==> jsx (get-deps)
ERROR: Failed to load erlang_rest_api/deps/trails/rebar.config: {error,
{34,
file,
{error,
function_clause,
[{erl_eval,
'-inside-an-interpreted-fun-',
[katana_test],
[]},
{erl_eval,
eval_fun,
6,
[{file,
"erl_eval.erl"},
{line,
829}]},
{erl_eval,
expr_list,
6,
[{file,
"erl_eval.erl"},
{line,
888}]},
{erl_eval,
expr,
5,
[{file,
"erl_eval.erl"},
{line,
240}]},
{erl_eval,
expr_list,
6,
[{file,
"erl_eval.erl"},
{line,
888}]},
{erl_eval,
expr,
5,
[{file,
"erl_eval.erl"},
{line,
240}]},
{erl_eval,
eval_lc1,
6,
[{file,
"erl_eval.erl"},
{line,
706}]},
{erl_eval,
eval_generate,
7,
[{file,
"erl_eval.erl"},
{line,
735}]}]}}}
make: *** [Makefile:7: deps] Error 1
katana_test seems to be some kind of testing tool. I tried adding that repos (inaka/katana-est) to rebar.config but it's not working, either.
I also tried tagging cowboy as version "2.5.0" as listed in "undefined" earlier, but that made no difference.
Do we really need to this specific, listing every dependent repository of every dependency?
I also tried using hex instead:
{jsx, ".*"},
{ranch, ".*"},
{trails, ".*"},
{cowboy_swagger, "2.1.0"}
but I still got:
Dependency not available: jsx-.* (undefined)
Dependency not available: trails-.* (undefined)
Dependency not available: cowboy_swagger-2.1.0 (undefined)
ERROR: compile failed while processing
Am I missing another dependency?
The problem arises from the fact that cowboy_swagger is built to be used with rebar3 and it's not compatible with the old rebar, but erlang_rest_api is using the old rebar, as you can see in its Makefile.
The solution to your problem may be as simple as using rebar3 to build the project. But careful if you do that since that would break make run and make run-local. You'll have to figure out how to achieve the same results using releases.
Related
I'm trying to create a release for my phoenix-framework project.
Everything is working fine, until my code need to do a specific action using :httpc module from OTP.
Apparently exrm, hasn't bundled the httpc module, and therefore could not find it.
I have tried to add it into my mix.exs application dependance, but as soon as I do, it will refuse to create a release due to an "error"
does anyone know how to fix this ?
For mix.env with :httpc as dependency :
$ MIX_ENV=prod mix release --verbosity=vebose
Building release with MIX_ENV=prod.
==> Generating relx configuration...
==> Generating sys.config...
==> Generating boot script...
==> Packaging consolidated protocols...
==> Generating release...
===> Starting relx build process ...
===> Resolving OTP Applications from directories:
/home/morgan/Documents/rateapi/_build/prod/lib
/home/morgan/Documents/rateapi/deps
/usr/local/lib/elixir/bin/../lib/eex/ebin
/usr/local/lib/elixir/bin/../lib/elixir/ebin
/usr/local/lib/elixir/bin/../lib/ex_unit/ebin
/usr/local/lib/elixir/bin/../lib/iex/ebin
/usr/local/lib/elixir/bin/../lib/logger/ebin
/usr/local/lib/elixir/bin/../lib/mix/ebin
/home/morgan/Documents/rateapi/lib
/usr/erlang/otp_R18B03/lib/erlang/lib
/home/morgan/Documents/rateapi/rel
==> ERROR: "Failed to build release. Please fix any errors and try again."
For mix.env without :httpc dependency :
** (exit) an exception was raised:
** (UndefinedFunctionError) function :httpc.request/4 is undefined (module :httpc is not available)
:httpc.request(:get, {'http://free.currencyconverterapi.com/api/v3/currencies', []}, [], [])
(fx_rates) web/controllers/rate_controller.ex:46: FxRates.V1.RateController.reload_currencies/0
(fx_rates) web/controllers/rate_controller.ex:66: FxRates.V1.RateController.show/2
(fx_rates) web/controllers/rate_controller.ex:1: FxRates.V1.RateController.action/2
(fx_rates) web/controllers/rate_controller.ex:1: FxRates.V1.RateController.phoenix_controller_pipeline/2
(fx_rates) lib/phoenix/router.ex:261: FxRates.Router.dispatch/2
(fx_rates) web/router.ex:1: FxRates.Router.do_call/2
(fx_rates) lib/fx_rates/endpoint.ex:1: FxRates.Endpoint.phoenix_pipeline/1
You may be missing the erlang-inets package. Try to install it or reinstall it again. If you are using Ubuntu you may install it with:
sudo apt-get install erlang-inets
Alternatively you may want to try adding the module :inets to your mix.exs application dependencies.
I set-up some dependencies in my rebar.config (which I have done previously in other projects)
rebar.config:
{sub_dirs, ["sbin", "priv"]}.
{lib_dirs, ["deps/erlang"]}.
{erl_opts, [{parse_transform, lager_transform}]}.
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
{cover_enabled, true}.
{cover_export_enabled, true}.
{deps, [
{lager, "2.0.3",
{git, "git://github.com/basho/lager.git", {tag, "2.0.3"}}},
{ezk, ".*",
{git, "git#github.com:campanja/ezk.git"}}
]}.
When I run rebare get-deps I am getting the following errors:
ERROR: Dependency dir /Users/me/workspace/erlang/try-ezk/deps/ezk failed application validation with reason:
{missing_app_file,"/Users/me/workspace/erlang/try-ezk/deps/ezk"}.
ERROR: 'get-deps' failed while processing /Users/me/workspace/erlang/try-ezk: rebar_abort
I'm really not sure what I'm doing wrong this time. Any help would be greatly appreciated.
did you try with this syntax:
{ezk, ".*",{git, "git://github.com/campanja/ezk.git"}}
I have a structure similar to the following:
rebar.config
deps/
apps/A/rebar.config
My top-level rebar.config file looks like the following:
{sub_dirs, ["apps/A"]}.
{lib_dirs, ["deps"]}.
A/rebar.config looks like the following:
{deps, [
%% deps
]}.
{erl_opts, [debug_info, warn_missing_spec, warnings_as_errors]}.
Now, one of my dependencies doesn't provide -spec for all of its functions, so the warnings_as_errors causes the compile to fail.
I was expecting the erl_opts to only affect my code, and for the dependencies to have their own options. Why does rebar do this?
It turns out that one of my dependencies doesn't have a rebar.config, so rebar is compiling it using my options.
What's confusing is that erl_opts is not set in the top-level rebar.config, but in a local rebar.config file. This is the file that has the deps clause.
It seems that the options are inherited "sideways" in this case.
I cannot reproduce this using the following version of rebar:
rebar 2.1.0-pre R15B03 20131210_073701 git 2.1.0-pre
On my local setup, using your same config (goldrush is my dependency):
...
==> goldrush (compile)
DEBUG: Matched required ERTS version: 5.9.3.1 -> .*
DEBUG: Matched required OTP release: R15B03 -> .*
DEBUG: Min OTP version unconfigured
DEBUG: erl_opts [debug_info,warn_export_all]
...
==> myapp (compile)
DEBUG: Matched required ERTS version: 5.9.3.1 -> .*
DEBUG: Matched required OTP release: R15B03 -> .*
DEBUG: Min OTP version unconfigured
DEBUG: erl_opts [debug_info,debug_info,warn_missing_spec,warnings_as_errors]
...
As you can see, the two applications receive two different sets of options.
Could you enable debugging and post the relevant output?
./rebar -vvv clean compile
What version of rebar/Erlang are you running?
I want to use lager as my log utility and I have orgnazied my proj as below:
proj\
|
|--lager\
| |--src\
| |--ebin\
| |--...
|
|--logserver\
| |--src\
| |--ebin\
| |--rebar.config
| |--...
|
|--rebar
|
However, when I try to compile logserver, I always got the following error:
D:\proj\logserver>..\rebar compile
==> logserver (compile)
src/logserver_app.erl:none: error in parse transform 'lager_transform': {undef,
[{lager_transform,
parse_transform,
[[{attribute,1,file,
{"src/logserver_app.erl",1}},
...
Can anyone know the reason? Thanks!
These is some additional information:
I am using Windows OS and using latest version of Erlang and rebar
and lager.
lager itself has already been compiled. We can find the D:\proj\logserver>dir ..\lager\ebin\lager_transform.beam (This will
succeed)
rebar's config file(D:\proj\logserver\rebar.config):
...
{erl_opts, [{parse_transform, lager_transform}, debug_info,{d,'TEST'}, {i, "include"}, {src_dirs, ["src"]}]}.
{lib_dirs, ["..\lager\ebin"]}.
...
If you already have lager in your deps then make sure that you move lager dependency first in rebar.config so that way it will compile first. Like so:
{deps,[
lager,
..
]}.
Did you add lager as a dependency in your rebar.config? I guess lager is not in the path.
From the rebar wiki:
To use lager in your application, you need to define it as a rebar dep
or have some other way of including it in erlang’s path. You can then
add the following option to the erlang compiler flags:
{parse_transform, lager_transform}
You can add 'lager' as a dependency by editing your rebar.config:
%% == Dependencies ==
%% Where to put any downloaded dependencies. Default is "deps"
{deps_dir, "deps"}.
%% What dependencies we have, dependencies can be of 3 forms, an application
%% name as an atom, eg. mochiweb, a name and a version (from the .app file), or
%% an application name, a version and the SCM details on how to fetch it (SCM
%% type, location and revision). Rebar currently supports git, hg, bzr and svn.
{deps, [application_name,
{application_name, "1.0.*"},
{application_name, "1.0.*",
{git, "git://github.com/basho/rebar.git", {branch, "master"}}}]}.
In your case, that should be something like:
{deps, [{lager, ".*", {git, "git://github.com/basho/lager.git", "HEAD"}}]}.
More info about the rebar dependency manager here:
https://github.com/basho/rebar/wiki/Dependency-management
I am trying to run rebar generate to generate a release for an erlang rebar project and getting the following error. Any ideas what I am doing wrong?
./rebar generate
Command 'generate' not understood or not applicable
I am on OSX with erlang version Erlang R14B03 and below is my rebar.conf
{lib_dirs, ["deps"]}.
{sub_dirs, ["rel"]}.
{deps, [
{folsom, ".*", {git, "git://github.com/boundary/folsom", "master"}}
]}.
{require_otp_vsn, "R14|R15"}.
{erl_opts, [
fail_on_warning,
debug_info,
warn_missing_spec
]}.
{clean_files, ["*.eunit", "ebin/*.beam", "rel/graphsom"]}.
{cover_enabled, true}.
{eunit_opts, [verbose, {report, {eunit_surefire, [{dir, "."}]}}]}.
You are getting this error because rebar is unable to find a release. You should check if you have reltool.config somewhere and rebar knows about it.
If no release exists, you can create a new one:
mkdir rel
cd rel
../rebar create-node nodeid=YOUR_NODE_ID
Lastly, you need to tell rebar about the release. In your case, you already have the following added to rebar.config:
{sub_dirs, ["rel"]}.
This should allow the generate command to build a new release.