How to save IP to the environment Variable in docker file?

Evaluating ENV value on build stage is not supported. See the thread here https://github.com/moby/moby/issues/29110

Since your app needs this value on execution phase you can build your image just from

FROM maven:3.6.3-openjdk-11

and then build it like this

docker build -t maven .

and then execute like this:

docker run -ti -e IP=$(ip -4 route show default | cut -d" " -f3) maven /bin/bash

Here is the result visible in container:

root@6856d118d02b:/# echo $IP
192.168.0.1