How to build jar when a project depence on other project with gradle

I have a project in Intellij Idea.
The root directory sturcture is like this:

MyProject:
  --ProjectA
       --build.gradle

  --ProjectCommon
       --build.gradle

  --settings.gradle

The ProjectA will use ProjectCommon’s class.

The contents of setting.gradle are as follows:

rootProject.name = 'MyProject'

include 'ProjectA'
include 'ProjectCommon'

the dependencies code snippet of ProjectA’s build.gradle:

  implementation project(':ProjectCommon')

I use ProjectCommon’s class in ProjectA. It is work and run successfully When I run with Intellij idea run configuration. Howerver There are some error when I build ProjectA.jar with gradle’s build task.The error is that error: package com.common.xxx not exist. (com.common package is in ProjectCommon and I use it’s class in ProjectA).

How to configure the gradle so can I build the ProjectA.jar sucessfully?