Matthew and Luke agree on Joseph and disagree about his father.
Two fathers for Joseph
Matthew: Jacob. Luke: Heli. The classic answers are a levirate marriage (Africanus), adoption (Augustine), Luke giving Mary’s line (Annius and after), or two independent traditions each making its own theological point. None has the field to itself.
The texts
15Eliud became the father of Eleazar. Eleazar became the father of Matthan. Matthan became the father of Jacob.
16Jacob became the father of Joseph, the husband of Mary, from whom was born Jesus, who is called Christ.
23Jesus himself, when he began to teach, was about thirty years old, being the son (as was supposed) of Joseph, the son of Heli,
24the son of Matthat, the son of Levi, the son of Melchi, the son of Jannai, the son of Joseph,
Readers
In order of date. Summaries are paraphrase; follow the citations for the texts themselves.
Letter to Aristides, preserved in Eusebius, Church History 1.7
The first surviving harmonization. Joseph had two fathers, one by nature and one by law: Matthew gives the natural line (Jacob), Luke the legal one (Heli), joined by a levirate marriage after Heli died childless. Africanus says the account came from the desposynoi, relatives of Jesus in Nazareth and Cochaba who kept private family records after Herod burned the public genealogies. He admits he has no testimony for this, only that no better or truer account is available.
On the Harmony of the Evangelists 2.1–4; Sermon 51; Retractations 2.16
Matthew says ‘begot’ (genuit), Luke ‘who was of’ (qui fuit): Luke may give the adoptive father. Matthew descends, bearing the sins Christ came to take; Luke ascends from the baptism, where sins are cleansed. Augustine counts forty generations in Matthew (the labor of this life) and seventy-seven in Luke (eleven sevens: eleven, the number of transgression beyond the ten commandments; seventy-seven, the number of forgiveness in Matthew 18:22). In the Retractations (2.16) he revised ‘adopted by the other’ to ‘adopted for the other’, accepting the levirate explanation.
Summa Theologiae III, q. 31, aa. 2–3; Catena Aurea on Matthew 1 and Luke 3
Christ took flesh from the stock of David through Mary, whose descent from David is presumed since Jews married within the tribe; the genealogy is traced through Joseph because Scripture reckons descent through men and because Joseph was Mary’s husband. The Catena gathers the patristic readings above verse by verse.
Commentaries on various ancient authors (1498)
Usually credited with originating the thesis that Luke gives Mary’s line: Heli is Mary’s father and Joseph his son by marriage. Annius was also a notorious forger of ancient texts, which has not stopped the thesis from outliving him.
In the tradition
Matthan · Patristic Julius Africanus (Letter to Aristides, in Eusebius, Church History 1.7): Matthan, of Solomon’s line, and Melchi, of Nathan’s, married the same woman, Estha, in succession. Jacob was Matthan’s son and Heli Melchi’s, so they were half-brothers by one mother. Heli died childless; Jacob married his widow under the levirate law and fathered Joseph, who was thus Jacob’s son by nature and Heli’s by law. Africanus says he had this from the Lord’s own relatives, the desposynoi.
Heli · Jewish A Talmudic vision of the afterlife (y. Hagigah 2:2, 77d) names a ‘Miriam bat ʿalei betzalim’, most naturally ‘daughter of onion-leaves’. A few have read the consonants as ‘daughter of Eli’ and linked her to Mary; the link is a stretch.
Joseph · Patristic Augustine, Sermon 51: Joseph is truly father, not by the flesh but by the marriage bond, and ‘the more chastely a father, the more firmly a father’; therefore the line may run through him. The Protevangelium of James makes him an elderly widower, Jerome a lifelong virgin.
Mary · Patristic Irenaeus and others argued Mary too was of David’s house, so that ‘from the seed of David according to the flesh’ (Rom 1:3) held of her. Aquinas takes this up in ST III q.31.