Heterogeneous cross-project defect prediction (HCPDP) aims to learn a prediction model from a heterogeneous source project and then apply the model to a target project. Existing HCPDP works mapped the data of the source and target projects in a common space. However, the pre-defined forms of mapping methods often limit prediction performance and it is difficult to measure the distance between two data instances from different feature spaces. This paper introduced optimal transport (OT) theory for the first time to build the relationship between source and target data distributions, and two prediction algorithms were proposed based on OT theory. In particular, an algorithm based on the entropic Gromov-Wasserstein (EGW) discrepancy was developed to perform the HCPDP model. The proposed EGW model measures the distance between two metric spaces by learning an optimal transfer matrix with the minimum data transfer cost and avoids measuring the distance of two instances of different feature spaces. Then, to improve EGW performance, an EGW+ transport algorithm based on EGW was developed by integrating target labels. Experimental results showed the effectiveness of EGW and EGW+ methods, and proved that our methods can support developers to find the defects in the early phase of software development.